Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Get Geometrical Set where Point is stored (Macro)

Status
Not open for further replies.

AlexMorasan

Automotive
Aug 17, 2020
13
0
0
MX
Hello everyone
I have made a macro with the purpose of creating some lines and planes to use as tangency elements in my designs. The user selects the part where the geometry will be created , then selects a point as reference to start creating all the other elements. This elements will be created inside a Geometrical Set named Aux_Geo, and this GS has to be created inside the geometrical set where the point is stored.

Here is my code:

Sub CATMain()

'--------------------------- Elements -------------------------------------------------------------------------------------
Dim Main_Routing As Document
Dim Main_PartB As Part
Dim Main_WireF_Elements As HybridBodies
Dim Main_GeoS As HybridBody
Dim Aux_WireF_Elements As HybridBodies
Dim Aux_GeoS As HybridBody
Dim Construction_Point As HybridShapePointCoord
Dim Point_Ref As Reference
Dim Wire_Factory As HybridShapeFactory
Dim Line_Dir As HybridShapeDirection
Dim Line_PD As HybridShapeLinePtDir
Dim Origin_Pl As HybridShapePlaneExplicit
Dim Plane_Ref As Reference
Dim Point_Ref_2 As Reference
Dim Plane_Off As HybridShapePlaneOffsetPt
Dim Line_Ref As Reference
Dim Plane_Off_X As Reference
Dim Angle_Line As HybridShapeLineAngle
Dim Angled_Plane As HybridShapePlaneAngle
Dim Plane_Angle_Ref As Reference
Dim Selected_Point As String
Dim Selected_Part As String
Dim ext As String
Dim USel As Selection
Dim USelLB
Dim InputObject(0)
Dim PartObject(0)
Dim oStatus
Dim Routings As Documents
Dim Routing_P As PartDocument
Dim WString As String

InputObject(0) = "Point"
PartObject(0) = "Part"
ext = ".CATPart"


'------------------------- Create Geometrical Set Inside other Geometrical Set --------------------------------------------

Set USel = CATIA.ActiveDocument.Selection
Set USelLB = USel
MsgBox "Select in the Specification tree the part where the tangency will be created. Press ESC to cancel"
oStatus = USelLB.SelectElement2(PartObject, "Select something in Specification Tree", False)
If (oStatus = "Cancel") Then
Exit Sub
Else
End If
'MsgBox (USel.Item(1).Value.Name), , "VBScript"
Selected_Part = USel.Item(1).Value.Name
USel.Clear

'------------------------- Create Geometrical Set Inside other Geometrical Set --------------------------------------------

Set Main_Routing = CATIA.ActiveDocument
Set Routings = CATIA.Documents
WString = Selected_Part & ext
'MsgBox WString
Set Routing_P = Routings.Item(WString)
'Set Main_PartB = Main_Routing.Part
Set Main_PartB = Routing_P.Part
Set Main_WireF_Elements = Main_PartB.HybridBodies
Set Main_GeoS = Main_WireF_Elements.Item("Geometrical Set.1")
Set Aux_WireF_Elements = Main_GeoS.HybridBodies
Set Aux_GeoS = Aux_WireF_Elements.Add()
Aux_GeoS.Name = "Aux_Geo"

'------------------------- Select Creation Point --------------------------------------------

Set USel = CATIA.ActiveDocument.Selection
Set USelLB = USel
MsgBox "Select the point where the tangency will be created. Press ESC to cancel"
oStatus = USelLB.SelectElement2(InputObject, "Select something in Specification Tree or the graphic area", False)
If (oStatus = "Cancel") Then
Exit Sub
Else
End If
'MsgBox (USel.Item(1).Value.Name), , "VBScript"
Selected_Point = USel.Item(1).Value.Name
USel.Clear

'------------------------- Create Line --------------------------------------------

Set Point_Ref = Main_PartB.CreateReferenceFromObject(Main_GeoS.HybridShapes.Item(Selected_Point))
Set Wire_Factory = Main_PartB.HybridShapeFactory
Set Line_Dir = Wire_Factory.AddNewDirectionByCoord(0, 0, 1)
Set Line_PD = Wire_Factory.AddNewLinePtDir(Point_Ref, Line_Dir, 0, 20, False)
Aux_GeoS.AppendHybridShape Line_PD

'------------------------- Create Plane --------------------------------------------

Set Origin_Pl = Main_PartB.OriginElements.PlaneZX
Set Plane_Ref = Main_PartB.CreateReferenceFromObject(Origin_Pl)
Set Plane_Off = Wire_Factory.AddNewPlaneOffsetPt(Origin_Pl, Point_Ref)
Aux_GeoS.AppendHybridShape Plane_Off

'------------------------- Create Angled Plane --------------------------------------------

Set Line_Ref = Main_PartB.CreateReferenceFromObject(Line_PD)
Set Plane_Off_X = Main_PartB.CreateReferenceFromObject(Plane_Off)
Set Angled_Plane = Wire_Factory.AddNewPlaneAngle(Plane_Off_X, Line_Ref, 45, False)
Aux_GeoS.AppendHybridShape Angled_Plane

'------------------------- Create Angled Line --------------------------------------------

'Set Line_Ref = Main_PartB.CreateReferenceFromObject(Line_PD)
'Set Plane_Off_X = Main_PartB.CreateReferenceFromObject(Plane_Off)
Set Plane_Angle_Ref = Main_PartB.CreateReferenceFromObject(Angled_Plane)
Set Angle_Line = Wire_Factory.AddNewLineAngle(Line_Ref, Plane_Angle_Ref, Point_Ref, False, 0, 100, 45, False)
Aux_GeoS.AppendHybridShape Angle_Line
Main_PartB.Update
End Sub

I have attached a picture of the result that I get.

The issue is that at first I thought we only had 1 geometrical set per Part, but some of my colleagues designs uses more than one so my macro wont be able to work properly for everyone. Is there anyway to know in which Geometrical set the point the user select is stored ? Or any ideas on how I can change my macro?

Thanks in advance for your support

Best Regards

Alex
 
 https://files.engineering.com/getfile.aspx?folder=0d5d9481-3676-43f7-b606-a2d037374d03&file=Capture.PNG
Replies continue below

Recommended for you

if you are not working in Hybrid Design, doing a "Define in Work Object" on a feature will select the geometrical set your feature belongs to...

regards,
LWolf
 
Status
Not open for further replies.
Back
Top