×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Catia V5 Macro to create Cylinders using Sweep and center curves

Catia V5 Macro to create Cylinders using Sweep and center curves

Catia V5 Macro to create Cylinders using Sweep and center curves

(OP)
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: Macro for normal to surface lines

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.



My input:


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

Kind regards,
Catalin

RE: Catia V5 Macro to create Cylinders using Sweep and center curves

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

RE: Catia V5 Macro to create Cylinders using Sweep and center curves

(OP)
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

RE: Catia V5 Macro to create Cylinders using Sweep and center curves

Your welcome Mr. Avram bigsmile

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources

eBook - Efficient and Effective Production Support with 3D Printed Jigs and Fixtures
Jigs and fixtures offer manufacturers a reliable process for delivering accurate, high-quality outcomes, whether for a specific part or feature, or for consistency across multiples of parts. Although the methodologies and materials for producing jigs and fixtures have evolved beyond the conventional metal tooling of years past, their position as a manufacturing staple remains constant due to the benefits they offer. Download Now
Overcoming Cutting Tool Challenges in Aerospace Machining
Aerospace manufacturing has always been on the cutting edge, from materials to production techniques. However, these two aspects of aerospace machining can conflict, as manufacturers strive to maintain machining efficiency with new materials by using new methods and cutting tools. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close