Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Can any body tell me to create a po 1

Status
Not open for further replies.

Neerajjo

Automotive
Jan 13, 2021
45
Can any body tell me to create a point on curve using user selection curve and point, please help.
 
Replies continue below

Recommended for you

Do you need a macro or looking for a standard command?

Please, provide more details.
 
Macro..... i want to create point on curve....but i want use user selection for curve and point to create point on curve.
 

I have made this code but its not working,,,,i want to give reference 1 and reference 2 using user selection. please help.





Sub CATMain()

Dim ActDoc As Object
Set ActDoc = CATIA.ActiveDocument

Dim part1 As Object
Set part1 = ActDoc.Part

Dim hybridBodies1 As Object
Set hybridBodies1 = part1.HybridBodies



Dim sSEL
Set sSEL = CATIA.ActiveDocument.Selection
sSEL.Clear

MsgBox "Please select Geometrical Set or Body where the curve is ..."

Dim EnableSelectionFor(1)
EnableSelectionFor(0) = "HybridBody"
EnableSelectionFor(1) = "Body"

Dim UserSelection
UserSelection = sSEL.SelectElement2(EnableSelectionFor, "Select Geometrical Set or Body ...", False)

Dim ohybridbody As Object
Set ohybridbody = sSEL.item(1).Value

MsgBox sSEL.item(1).Value.Name


Dim sSEL1
Set sSEL1 = CATIA.ActiveDocument.Selection
sSEL1.Clear

MsgBox "Please select Geometrical Set or Body where the points is ..."

Dim EnableSelectionFor1(1)
EnableSelectionFor1(0) = "HybridBody"
EnableSelectionFor1(1) = "Body"

Dim UserSelection1
UserSelection1 = sSEL1.SelectElement2(EnableSelectionFor1, "Select Geometrical Set or Body ...", False)

Dim ohybridbody1 As Object
Set ohybridbody1 = sSEL.item(1).Value

MsgBox sSEL1.item(1).Value.Name





Dim reference1 As Reference
Set reference1 = part1.CreateReferenceFromObject(ohybridbody)
MsgBox reference1.Name

Dim reference2 As Reference
Set reference2 = part1.CreateReferenceFromObject(ohybridbody1)
MsgBox reference2.Name

Dim hybridShapeFactory1 As HybridShapeFactory
Set hybridShapeFactory1 = part1.HybridShapeFactory

Dim hybridShapePointOnCurve1 As HybridShapePointOnCurve
Set hybridShapePointOnCurve1 = hybridShapeFactory1.AddNewPointOnCurveWithReferenceFromDistance(reference1, reference2, 5#, True)

hybridShapePointOnCurve1.DistanceType = 1



part1.InWorkObject = hybridShapePointOnCurve1

part1.Update





End Sub
 
I have made it , thanks..for your support.



Sub CATMain()

Dim partDocument1 As PartDocument
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.Item("Geometrical Set.1")


'selection of curve


Dim varSelection As Variant
Set varSelection = partDocument1.Selection

ReDim sFilter(1)
MsgBox "Select Curve"
sFilter(0) = "HybridShapeCurveExplicit"
sFilter(1) = "MonoDim"

sStatus1 = varSelection.SelectElement2(sFilter, "Select Curve", False)

Dim oCurve As Object
Set oCurve = varSelection.Item(1).Value

Dim reference1 As Reference

Set reference1 = part1.CreateReferenceFromObject(oCurve)


'Selection of Point




Dim Selection1 As Object
Set Selection1 = CATIA.ActiveDocument.Selection

ReDim InPutObjectType(0)
MsgBox "Select Point"
'InPutObjectType(0) = "CATPoint"
'InPutObjectType(0) = "AnyObject"
InPutObjectType(0) = "Point"
Status = Selection1.SelectElement2(InPutObjectType, "Select a point", False)

Dim opoint As Object
Set opoint = Selection1.Item(1).Value

Dim reference2 As Reference

Set reference2 = part1.CreateReferenceFromObject(opoint)



'Creating point




Dim hybridShapeFactory1 As HybridShapeFactory
Set hybridShapeFactory1 = part1.HybridShapeFactory

Dim hybridShapePointOnCurve1 As HybridShapePointOnCurve
Set hybridShapePointOnCurve1 = hybridShapeFactory1.AddNewPointOnCurveWithReferenceFromDistance(reference1, reference2, 20#, False)

hybridShapePointOnCurve1.DistanceType = 1

hybridBody1.AppendHybridShape hybridShapePointOnCurve1

part1.InWorkObject = hybridShapePointOnCurve1

part1.Update

End Sub

 
I want to know the macro which can measure length of curve selected by user.basically i want to create multipoints on curve for which i need length of curve.
 
i have tried this code for measuring the length... but error 91 is coming.... please help.


Dim SpaWorkbench As SpaWorkbench
Dim theMeasurable As Measurable


Set theMeasurable = SpaWorkbench.GetMeasurable(oCurve)

MsgBox theMeasurable.Length
 
Code:
set SpaWorkbench = partDocument1.GetWorkbench("SPAWorkbench")
set theMeasurable = spaWorkbench.GetMeasurable(part1.CreateReferenceFromObject(oCurve))
 
Thanks code is working...But how to check the length, how to print.
 
when i use :

Msgbox theMeasurable.Length


it shows error 440.
 
Capture_ptdnc2.png


again error.
 
Maybe your curve hasn't been updated?

Post your full code as well as sample CATPart.
 
Sub CATMain()

Dim partDocument1 As PartDocument
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.Item("Geometrical Set.1")


'selection of curve


Dim varSelection As Variant
Set varSelection = partDocument1.Selection

ReDim sFilter(1)
MsgBox "Select Curve"
sFilter(0) = "HybridShapeCurveExplicit"
sFilter(1) = "MonoDim"

sStatus1 = varSelection.SelectElement2(sFilter, "Select Curve", False)

Dim oCurve As Object
Set oCurve = varSelection.Item(1).Value

Dim reference1 As Reference

Set reference1 = part1.CreateReferenceFromObject(oCurve)



' Calculate curve length



Dim SpaWorkbench As SpaWorkbench
Dim theMeasurable As Measurable

Set SpaWorkbench = partDocument1.GetWorkbench("SPAWorkbench")
Set theMeasurable = SpaWorkbench.GetMeasurable(part1.CreateReferenceFromObject(oCurve))

part1.Update

MsgBox CStr(theMeasurable.Length)


'Selection of Point




Dim Selection1 As Object
Set Selection1 = CATIA.ActiveDocument.Selection

ReDim InPutObjectType(0)
MsgBox "Select Point"
'InPutObjectType(0) = "CATPoint"
'InPutObjectType(0) = "AnyObject"
InPutObjectType(0) = "Point"
Status = Selection1.SelectElement2(InPutObjectType, "Select a point", False)

Dim opoint As Object
Set opoint = Selection1.Item(1).Value

Dim reference2 As Reference

Set reference2 = part1.CreateReferenceFromObject(opoint)



'Creating point




Dim hybridShapeFactory1 As HybridShapeFactory
Set hybridShapeFactory1 = part1.HybridShapeFactory

Dim hybridShapePointOnCurve1 As HybridShapePointOnCurve
Set hybridShapePointOnCurve1 = hybridShapeFactory1.AddNewPointOnCurveWithReferenceFromDistance(reference1, reference2, 20#, False)

hybridShapePointOnCurve1.DistanceType = 1

hybridBody1.AppendHybridShape hybridShapePointOnCurve1

part1.InWorkObject = hybridShapePointOnCurve1

part1.Update

End Sub
 
in my cat part i simply making curve and point on curve and than run this code.
 
Please help how to print length of curve.
 
Try selecting curve in specification tree. When you select it from a 3D-spapce it's edge gets selected instead.
Edge itself is a reference so you don't need to call CreateReferenceFromObject() for it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor