×
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 – How to Choose the Correct Corrosion Testing Method
When designing a metal component, engineers have to consider how susceptible certain alloys are to corrosion in the final product’s operating environment. In a recent study by NACE (National Association of Corrosion Engineers), it was estimated that the direct and indirect costs of corrosion in the United States is approximately 6.2% of the GDP. In 2016, that cost exceeded $1 trillion dollars for the first time. 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