Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Points on Surface and normal line creation 1

Status
Not open for further replies.

DomKum

Automotive
Nov 27, 2005
23
IN
Hi All,

I am trying to create macro with input as GS in which only Surfaces are there and output expected is to create a point which is CG of each surface and then create a normal to respective surface with respective point as input.

I need help in putting this macro in loop i mean point and line to be created for all the surfaces in the input GS.
When I try to run this macro its failing in LINE 41 WHICH I have highlighted in red color.

Thanks in advance for any suggestion or guidance.


Language="VBSCRIPT"

Sub CATMain()

Set partDocument1 = CATIA.ActiveDocument

Set part1 = partDocument1.Part

Set hybridBodies1 = part1.HybridBodies

'Set hybridShapeFactory1 = part1.HybridShapeFactory

Set parameters1 = part1.Parameters

MsgBox "Select Geometrical set."

Dim oSelection ' 'As Selection
Dim InputObjectType(0)

Set oSelection = CATIA.ActiveDocument.Selection
oSelection.Clear
InputObjectType(0) = "HybridBody"
Status = oSelection.SelectElement2(InputObjectType, "Select Geometrical set.", True)



Set hybridShapeFactory1 = part1.HybridShapeFactory

Set parameters1 = part1.Parameters

Set hybridShapeSurfaceExplicit1 = parameters1.Item("Surface.679") 'this is one of the surfaces in my GS but I want for all the surfaces in GS

Set hybridBody1 = hybridBodies1.Add()

part1.UpdateObject hybridBody1

Set reference1 = part1.CreateReferenceFromObject(hybridShapeSurfaceExplicit1)

Set parameters2 = part1.Parameters

[highlight #CC0000]Set hybridShapePointExplicit1 = parameters2.Item("")[/highlight]

Set reference2 = part1.CreateReferenceFromObject(hybridShapePointExplicit1)

Set hybridShapeLineNormal1 = hybridShapeFactory1.AddNewLineNormal(reference1, reference2, 0.000000, 1000.000000, False)

hybridBody1.AppendHybridShape hybridShapeLineNormal1

part1.InWorkObject = hybridShapeLineNormal1

part1.Update

End Sub
 
Replies continue below

Recommended for you


Finally I could able to create FOR LOOP with displaying the count.

Can any one help me to create point on surface since I am unable to find the correct syntax.
This will help me to go forward.

Language="VBSCRIPT"

Sub CATMain()

Set partDocument1 = CATIA.ActiveDocument

Set part1 = partDocument1.Part

Set hybridBodies1 = part1.HybridBodies

Set hybridBody1 = hybridBodies1.Add()
Set hybridBody1 = CATIA.ActiveDocument.Part.InWorkObject

part1.UpdateObject hybridBody1

Dim InputObjectType(0)

Set oSelection = CATIA.ActiveDocument.Selection
oSelection.Clear
InputObjectType(0) = "HybridBody"
Status = oSelection.SelectElement2(InputObjectType, "Select Geometrical set.", True)

Dim iCount
Dim i 'As Integer

oSelection.Search "CATGmoSearch.Surface,sel"
iCount = oSelection.Count

For i =1 to iCount
msgbox ("number " & i)

Set hybridShapeFactory1 = part1.HybridShapeFactory

Set hybridShapeDirection1 = hybridShapeFactory1.AddNewDirectionByCoord(0.807715, -0.589573, 0.000000)

Set parameters1 = part1.Parameters

Set hybridShapeSurfaceExplicit1 = parameters1.Item(i)

Set reference1 = part1.CreateReferenceFromObject(hybridShapeSurfaceExplicit1)


Set hybridShapePointOnSurface1 = hybridShapeFactory1.AddNewPointOnSurface(reference1, hybridShapeDirection1, 0.000000)

part1.InWorkObject = hybridShapePointOnSurface1

part1.Update

Next

End Sub
 
Datum geometry should not be retrieved from Parameters collection.

In your case simply get it from selection as you've already searched for all surfaces:

Code:
Set hybridShapeSurfaceExplicit1 = oSelection.Item(i).Value
 
Thank you for kind response.
The only good thing in this code is it can display the number of Surfaces in a selected GS.
However the point is not getting created.

Language="VBSCRIPT"

Sub CATMain()

Set partDocument1 = CATIA.ActiveDocument

Set part1 = partDocument1.Part

Set hybridBodies1 = part1.HybridBodies

Set hybridBody1 = hybridBodies1.Add()
Set hybridBody1 = CATIA.ActiveDocument.Part.InWorkObject

part1.UpdateObject hybridBody1

Dim InputObjectType(0)

Set oSelection = CATIA.ActiveDocument.Selection
oSelection.Clear
InputObjectType(0) = "HybridBody"
Status = oSelection.SelectElement2(InputObjectType, "Select Geometrical set.", True)

Dim iCount
Dim i 'As Integer

oSelection.Search "CATGmoSearch.Surface,sel"
iCount = oSelection.Count

For i =1 to iCount

msgbox ("number " & i) '----> Display the number of surfaces selected in a GS

Set hybridShapeFactory1 = part1.HybridShapeFactory

Set hybridShapeSurfaceExplicit1 = oSelection.Item(i).Value

Set reference1 = part1.CreateReferenceFromObject(hybridShapeSurfaceExplicit1)

Set hybridShapeDirection1 = hybridShapeFactory1.AddNewDirectionByCoord(0.807715, -0.589573, 0.000000)

Set hybridShapePointOnSurface1 = hybridShapeFactory1.AddNewPointOnSurface(reference1, hybridShapeDirection1, 0.000000)

part1.InWorkObject = hybridShapePointOnSurface1

part1.Update

Next

End Sub
 
It does get created, you have to place new feature in a desired container (body or geometrical set) manually with AppendHybridShape:

Code:
Set hybridShapePointOnSurface1 = hybridShapeFactory1.AddNewPointOnSurface(reference1, hybridShapeDirection1, 0.000000)
hybridBody1.HybridShapes.AppendHybridShape hybridShapePointOnSurface1

I insist you download ferdo's great "Portable Script Center" and refer to it's samples.
 
Mission accomplished.
Thank you Little Cthulhu for your patience and guidance.
Below is the MACRO for creating a point and Normal to surface line on input Surface in a GS.
Hope this will help new beginners like me.

'---------------------------------------
'This Macro is to create a point on Dead Surface
'in a selected Geometrical Set
'----------------------------------------
Language="VBSCRIPT"

Sub CATMain()

Set partDocument1 = CATIA.ActiveDocument

Set part1 = partDocument1.Part

Set hybridBodies1 = part1.HybridBodies

'part1.UpdateObject hybridBody1

Dim InputObjectType(0)

msgbox ("Select the geometrical set")

Set oSelection = CATIA.ActiveDocument.Selection
oSelection.Clear
InputObjectType(0) = "HybridBody"
Status = oSelection.SelectElement2(InputObjectType, "Select Geometrical set.", True)

Set hybridBody1 = hybridBodies1.Add()
Set hybridBody1 = CATIA.ActiveDocument.Part.InWorkObject

Dim iCount
Dim i 'As Integer

oSelection.Search "CATGmoSearch.Surface,sel" '-----With this all the surfaces will be searched in a selected GS
iCount = oSelection.Count '-----Each selected item is counted

For i =1 to iCount
'----------------
'Below line msgbox can be made as comment. This line is only for displaying the
'total number of Surfaces available in a selected GS
'----------------

msgbox ("number " & i)

set hybridShapeFactory1 = part1.HybridShapeFactory

Set hybridShapeSurfaceExplicit1 = oSelection.Item(i).Value

Dim reference1 'As Reference

Set reference1 = part1.CreateReferenceFromObject(hybridShapeSurfaceExplicit1)

Set hybridShapeDirection1 = hybridShapeFactory1.AddNewDirectionByCoord(0.5, 0.5, 0.000000)

Dim hybridShapePointOnSurface1 'As HybridShapePointOnSurface
Set hybridShapePointOnSurface1 = hybridShapeFactory1.AddNewPointOnSurface(reference1, hybridShapeDirection1, 0.000000)

hybridBody1.AppendHybridShape hybridShapePointOnSurface1

part1.InWorkObject = hybridShapePointOnSurface1

'Set reference2 = part1.CreateReferenceFromObject(hybridShapePointCoord1)

Set reference2 = hybridShapePointOnSurface1 '---->Created point is taken as reference to create a line

Set hybridShapeLineNormal1 = hybridShapeFactory1.AddNewLineNormal(reference1, reference2, 0.000000, 100.000000, False)

hybridBody1.AppendHybridShape hybridShapeLineNormal1

part1.InWorkObject = hybridShapeLineNormal1

part1.Update

Next

End Sub
 
MACRO is updated to rename the point and line created with parent surface name.
Any suggestion to improvements this will be helpful to me as well new beginners.
'---------------------------------------
'This Macro is to create a point on Dead Surface
'in a selected Geometrical Set
'----------------------------------------
Language="VBSCRIPT"

Sub CATMain()

Set partDocument1 = CATIA.ActiveDocument

Set part1 = partDocument1.Part

Set hybridBodies1 = part1.HybridBodies

'part1.UpdateObject hybridBody1

Dim InputObjectType(0)

msgbox ("Select the geometrical set")

Set oSelection = CATIA.ActiveDocument.Selection
oSelection.Clear
InputObjectType(0) = "HybridBody"
Status = oSelection.SelectElement2(InputObjectType, "Select Geometrical set.", True)

Set hybridBody1 = hybridBodies1.Add()
Set hybridBody1 = CATIA.ActiveDocument.Part.InWorkObject

Dim iCount
Dim i 'As Integer

oSelection.Search "CATGmoSearch.Surface,sel" '-----With this all the surfaces will be searched
iCount = oSelection.Count '-----Each selected item is counted

For i =1 to iCount
'----------------
'Below line msgbox can be made as comment. This line is only for displaying the
'total number of Surfaces available in a selected GS
'----------------

'msgbox ("number " & i) '--- It will display only count but not the name of item selected

'msgbox (i) '-----this will only display the number or count

'-----------With the statement as below each item name in the selected GS will be displayed
Set USel = CATIA.ActiveDocument.Selection
MsgBox(USel.Item(i).Value.Name)
'--------------- 09-Macro_to_display_selected_items.catvbs - reference macro for this statement

set hybridShapeFactory1 = part1.HybridShapeFactory

Set hybridShapeSurfaceExplicit1 = oSelection.Item(i).Value

Dim reference1 'As Reference

Set reference1 = part1.CreateReferenceFromObject(hybridShapeSurfaceExplicit1)

Set hybridShapeDirection1 = hybridShapeFactory1.AddNewDirectionByCoord(0.5, 0.5, 0.000000)

Dim hybridShapePointOnSurface1 'As HybridShapePointOnSurface
Set hybridShapePointOnSurface1 = hybridShapeFactory1.AddNewPointOnSurface(reference1, hybridShapeDirection1, 0.000000)

hybridBody1.AppendHybridShape hybridShapePointOnSurface1

part1.InWorkObject = hybridShapePointOnSurface1


'----> Below line will rename the new point created with sufix as POINT & PARENT SURFACE NAME
hybridShapePointOnSurface1.name = "Point for - " & USel.Item(i).Value.Name

Set reference2 = hybridShapePointOnSurface1 '---->Created point is taken as reference to create a line

Set hybridShapeLineNormal1 = hybridShapeFactory1.AddNewLineNormal(reference1, reference2, 0.000000, 50.000000, False)

hybridBody1.AppendHybridShape hybridShapeLineNormal1

part1.InWorkObject = hybridShapeLineNormal1

'---->Below line will rename the new LINE created with sufix as LINE & PARENT SURFACE NAME
hybridShapeLineNormal1.name = "Line for - " & USel.Item(i).Value.Name


part1.Update

Next

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top