Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Catia V5 Macro to create Cylinders using Sweep and center curves 1

Status
Not open for further replies.

Catalin_2018

Mechanical
Nov 14, 2018
2
Hello everybody,

I'm writing here in order to ask for your help. I'm not a good programmer! :)
My request is based to post: thread560-332713

In my case I have next structure:
Input: a geometrical set which contains a lot of lines (created with macro from the post mentioned above) - more than 2000 lines
Output: a new geometrical set that contain Sweeps (profile type: circle) using each line as "Center curve" and a "Radius" defined into macro.

sweep_01_ps14qo.png


My input:
1_qistou.jpg


Thank you in advance for your support, I really appreciate your work!

Kind regards,
Catalin
 
Replies continue below

Recommended for you

here is a piece of code that does the same thing

Option Explicit
Dim i As Integer
Dim mySel As Selection
Dim myPrt As Part
Dim myHB As HybridBody
Dim mySurfRef, myPointRef, myLineRef As Reference
Dim HS_Factory As HybridShapeFactory
Dim HS_Surf As HybridShapeSurfaceExplicit
Dim nLine As HybridShapeLineNormal
Dim myDir As HybridShapeDirection
Dim myCyl As HybridShapeCylinder
Sub CATMain()
Set myPrt = CATIA.ActiveDocument.Part
'this set must contain only one surface and n points
Set myHB = myPrt.HybridBodies.Item("Geometrical Set.1")
Set HS_Factory = myPrt.HybridShapeFactory
Set mySel = CATIA.ActiveDocument.Selection
'Search for GSD lines and points (the order is important)
mySel.Search "('Generative Shape Design'.Surface + 'Generative Shape Design'.Point);sel"
'In the selection we have the surface as the first item
Set mySurfRef = myPrt.CreateReferenceFromObject(mySel.Item(1).Value)
For i = 2 To mySel.Count
'create reference from point and use it later in the cylinder creation
Set myPointRef = myPrt.CreateReferenceFromObject(mySel.Item(i).Value)
'make the normal line
Set nLine = HS_Factory.AddNewLineNormal(mySurfRef, myPointRef, -15#, 15#, False)
myHB.AppendHybridShape nLine
'Give line a name
nLine.Name = "nLine-" & i - 1
myPrt.InWorkObject = nLine
'make a reference from this line because we use it as direction
Set myLineRef = myPrt.CreateReferenceFromObject(nLine)
Set myDir = HS_Factory.AddNewDirection(myLineRef)
Set myCyl = HS_Factory.AddNewCylinder(myPointRef, 2#, 15#, 15#, myDir)
'make the cylinder and name it
myHB.AppendHybridShape myCyl
myCyl.Name = "myCyl-" & i - 1
myPrt.InWorkObject = myCyl
myPrt.Update
Set myCyl = Nothing
Set myDir = Nothing
Set myLineRef = Nothing
Set nLine = Nothing
Set myPointRef = Nothing
Next i
mySel.Clear
Set mySurfRef = Nothing
Set mySel = Nothing
Set HS_Factory = Nothing
Set myHB = Nothing
Set myPrt = Nothing
End Sub
 
Thank you very much John! ;)
You saved my time!

I adapted a little your code because of some errors:

Option Explicit
Dim i As Integer
Dim mySel As Selection
Dim myPrt As Part
Dim myHB As HybridBody
Dim mySurfRef, myPointRef, myLineRef As Reference
Dim HS_Factory As HybridShapeFactory
Dim HS_Surf As HybridShapeSurfaceExplicit
Dim nLine As HybridShapeLineNormal
Dim myDir As HybridShapeDirection
Dim myCyl As HybridShapeCylinder

Sub CATMain()
Set myPrt = CATIA.ActiveDocument.Part
'this set must contain only one surface and n points
Set myHB = myPrt.HybridBodies.Item("Geometrical Set.1")
Set HS_Factory = myPrt.HybridShapeFactory
Set mySel = CATIA.ActiveDocument.Selection
'Search for GSD lines and points (the order is important)
mySel.Search "('Generative Shape Design'.Surface + 'Generative Shape Design'.Point);sel"
'In the selection we have the surface as the first item
Set mySurfRef = myPrt.CreateReferenceFromObject(mySel.Item(1).Value)
For i = 2 To mySel.Count
'create reference from point and use it later in the cylinder creation
Set myPointRef = myPrt.CreateReferenceFromObject(mySel.Item(i).Value)
'make the normal line
Set nLine = HS_Factory.AddNewLineNormal(mySurfRef, myPointRef, -15, 15, False)
myHB.AppendHybridShape nLine
'Give line a name
nLine.Name = "nLine-" & i - 1
myPrt.InWorkObject = nLine
'make a reference from this line because we use it as direction
Set myLineRef = myPrt.CreateReferenceFromObject(nLine)
Set myDir = HS_Factory.AddNewDirection(myLineRef)

Set myCyl = HS_Factory.AddNewCylinder(myPointRef, 2, 15, 15, myDir)
'make the cylinder and name it
myHB.AppendHybridShape myCyl
myCyl.Name = "myCyl-" & i - 1
myPrt.InWorkObject = myCyl
myPrt.Update
Set myCyl = Nothing
Set myDir = Nothing
Set myLineRef = Nothing
Set nLine = Nothing
Set myPointRef = Nothing
Next 'i
mySel.Clear
Set mySurfRef = Nothing
Set mySel = Nothing
Set HS_Factory = Nothing
Set myHB = Nothing
Set myPrt = Nothing

End Sub

Kind regards!
Catalin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor