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!

Points and Planes repetition Command in macro

Status
Not open for further replies.

peterbeamish1

Automotive
Aug 16, 2013
13
0
0
CA
Hey Guys!

Just wondering if anyone knows how to access the points and plane command (GSD), thru VBA. Alternatively, does anyone have an effective way of mass point creation on specified curves?

I need to make these points in a macro because further modifications will be made to the points by the script. This macro will be creating 1000+ points in a part document.


Thanks!
 
Replies continue below

Recommended for you

The code I get recording this command gives me manual creation of each point.

Can I loop the creation instead? If so how do I add points to an array in a way that allows me to access them as individual objects?

The code below is a snippet of the recording, each point is created individually on the curve. Does you record offer ONE command to do this?

Thanks,

Peter

CODE:
....

Dim hybridShapePointOnCurve1 As HybridShapePointOnCurve
Set hybridShapePointOnCurve1 = hybridShapes1.Item("Point.1")

Dim reference2 As Reference
Set reference2 = part1.CreateReferenceFromObject(hybridShapePointOnCurve1)

Dim hybridShapeFactory1 As HybridShapeFactory
Set hybridShapeFactory1 = part1.HybridShapeFactory

Dim hybridShapePointOnCurve2 As HybridShapePointOnCurve
Set hybridShapePointOnCurve2 = hybridShapeFactory1.AddNewPointOnCurveWithReferenceFromDistance(reference1, reference2, 0#, False)

hybridShapePointOnCurve2.DistanceType = 1

hybridBody1.AppendHybridShape hybridShapePointOnCurve2

part1.InWorkObject = hybridShapePointOnCurve2

part1.Update

Dim parameters1 As Parameters
Set parameters1 = part1.Parameters

Dim length1 As Length
Set length1 = parameters1.Item("Point\Length")


....

 
This depends on how you want to create the points, you need to get some references (name of the curve, length, starting point, a.s.o.).

Bellow is a code just to get the references name and length of the curve (what is commented is from an older macro, how to create a number of offset planes)

Code:
Language="VBSCRIPT"
Sub CATMain()

Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument

Dim part1 As Part
Set part1 = partDocument1.Part

Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies

Dim hybridBody1 As HybridBody
Set hybridBody1 = hybridBodies1.Add()

Dim hybridShapeFactory1 As Factory
Set hybridShapeFactory1 = part1.HybridShapeFactory

Dim axisSystems1 As AxisSystems
Set axisSystems1 = part1.AxisSystems

Dim InputObjectType(0)
 Set Document = CATIA.ActiveDocument
 Set Selection = Document.Selection
 'We propose to the user that he select a curve
 InputObjectType(0)="MonoDim"
 Status=Selection.SelectElement2(InputObjectType,"Select a curve",true)
 if (Status = "cancel") then Exit Sub
 Set Curve = Selection.Item(1).Value
 
 MsgBox Curve.name 
 
 Set FirstCurve = Selection.Item(1).Reference
Dim mySPA
Set mySPA = Document.GetWorkbench("SPAWorkbench")
Set mymeasurable = mySPA.GetMeasurable(FirstCurve)

MsgBox mymeasurable.length

'~ Dim axisSystem1 As AxisSystem
'~ Set axisSystem1 = axisSystems1.Item("Absolute Axis System")

'~ For j = 30 to 600 step 30  'added 
'~ Dim reference1 As Reference
'~ Set reference1 = part1.CreateReferenceFromBRepName("RSur:(Face:(Brp:(AxisSystem.1;1);None:();Cf11:());WithPermanentBody;WithoutBuildError;WithSelectingFeatureSupport;MFBRepVersion_CXR15)", axisSystem1)
'~ Dim hybridShapePlaneOffset1 As HybridShapePlaneOffset
'~ Set hybridShapePlaneOffset1 = hybridShapeFactory1.AddNewPlaneOffset(reference1, j, False)
'~ hybridBody1.AppendHybridShape hybridShapePlaneOffset1
'~ part1.InWorkObject = hybridShapePlaneOffset1
'~ Next 'added

'~ For j = 30 to 600 step 30  'added 
'~ Dim reference2 As Reference
'~ Set reference2 = part1.CreateReferenceFromBRepName("RSur:(Face:(Brp:(AxisSystem.1;3);None:();Cf11:());WithPermanentBody;WithoutBuildError;WithSelectingFeatureSupport;MFBRepVersion_CXR15)", axisSystem1)
'~ Dim hybridShapePlaneOffset2 As HybridShapePlaneOffset
'~ Set hybridShapePlaneOffset2 = hybridShapeFactory1.AddNewPlaneOffset(reference2, j, False)
'~ hybridBody1.AppendHybridShape hybridShapePlaneOffset2
'~ part1.InWorkObject = hybridShapePlaneOffset2
'~ Next 'added

'~ part1.Update 
      '~ ' --- Screen "Fit all"
      '~ Set specsAndGeomWindow1 = CATIA.ActiveWindow
      '~ Set viewer3D1 = specsAndGeomWindow1.ActiveViewer
      '~ viewer3D1.Reframe 
      '~ Set viewpoint3D1 = viewer3D1.Viewpoint3D

End Sub

Regards
Fernando

 
Are you in VBA or CATScript/catvbs? You could have the user select the curve and input the number of points they want on the curve, capture the length of the selected curve, place a start point on the curve, place points on the curve, then place normal planes through the points. But as ferdo mentioned, we need to know exactly what you want to do.

Other things you will likely need to do are check if the person entered an integer for the number of points and check if the points are traveling down the curve (sometimes the can be a along a curve but they go the wrong direction and float in space).
 
Status
Not open for further replies.
Back
Top