Measure Distance - Point to Surface
Measure Distance - Point to Surface
(OP)
Further to my recent post - refer to "thread560-433573: Measuring Area of a Fill Surface"
I wish to avoid using SPAWorkBench to return a Distance Measure Value
I also wish to create a loop whereby I Measure between a Surface and a number of Points sequencially
I recorded the manual method and altered it as per the advise in the thread above but it
does not create the Formula Relation correctly
Can anyone please advise - thanks
My test code below and attached:-
Language="VBSCRIPT"
Sub CATMain()
Set partDocument1 = CATIA.ActiveDocument
Set part1 = partDocument1.Part
Set parameters1 = part1.Parameters
Set length1 = parameters1.CreateDimension("DIST_PARAMETER", "LENGTH", 0.000000)
Set relations1 = part1.Relations
' Recorded Create Formula code line
'Set formula1 = relations1.CreateFormula("FORMULA", "", length1, "distance(`Surfaces\Sweep-ISOLATED` ,Points1\Point.1 ) ")
'* To put this functionality into a Loop, I need to pass different objects into the CreateFormula method
'* Further to Forum Thread = thread560-433573: Measuring Area of a Fill Surface, I have built a String to represent the Object Name (including Parent GeoSet)
strSurfaceObjectName = "Surfaces\Sweep-ISOLATED"
'* Test Message
' MsgBox "Surface Name = " & strSurfaceObjectName
strPointObjectName = "Points1\Point.1"
'* Test Message
' MsgBox "Point Name = " & strPointObjectName
' Create Formula Using A Manually Built String - As Per Advise For AREA Measurement
Set formula1 = relations1.CreateFormula("Dist_Formula", "", length1, "distance( " & strSurfaceObjectName & ", " & strPointObjectName & ") ")
'* Test Message
MsgBox "Distance Measure Value = " & length1.Value
part1.Update
End Sub
I wish to avoid using SPAWorkBench to return a Distance Measure Value
I also wish to create a loop whereby I Measure between a Surface and a number of Points sequencially
I recorded the manual method and altered it as per the advise in the thread above but it
does not create the Formula Relation correctly
Can anyone please advise - thanks
My test code below and attached:-
Language="VBSCRIPT"
Sub CATMain()
Set partDocument1 = CATIA.ActiveDocument
Set part1 = partDocument1.Part
Set parameters1 = part1.Parameters
Set length1 = parameters1.CreateDimension("DIST_PARAMETER", "LENGTH", 0.000000)
Set relations1 = part1.Relations
' Recorded Create Formula code line
'Set formula1 = relations1.CreateFormula("FORMULA", "", length1, "distance(`Surfaces\Sweep-ISOLATED` ,Points1\Point.1 ) ")
'* To put this functionality into a Loop, I need to pass different objects into the CreateFormula method
'* Further to Forum Thread = thread560-433573: Measuring Area of a Fill Surface, I have built a String to represent the Object Name (including Parent GeoSet)
strSurfaceObjectName = "Surfaces\Sweep-ISOLATED"
'* Test Message
' MsgBox "Surface Name = " & strSurfaceObjectName
strPointObjectName = "Points1\Point.1"
'* Test Message
' MsgBox "Point Name = " & strPointObjectName
' Create Formula Using A Manually Built String - As Per Advise For AREA Measurement
Set formula1 = relations1.CreateFormula("Dist_Formula", "", length1, "distance( " & strSurfaceObjectName & ", " & strPointObjectName & ") ")
'* Test Message
MsgBox "Distance Measure Value = " & length1.Value
part1.Update
End Sub





RE: Measure Distance - Point to Surface
distance(Surfaces\Sweep-ISOLATED, Points1\Point.1 ) is what you use
You should use `and not ' <- I think that your mistake is here
try to build the complete string before like
myMeasureString = "distance( `" & strSurfaceObjectName & "`, " `& strPointObjectName & "` ) "
then use it in formula
Set formula1 = relations1.CreateFormula("Dist_Formula", "", length1, myMeasureString )
indocti discant et ament meminisse periti
RE: Measure Distance - Point to Surface
A strange observation I have made is that the GeoSet and Point string can be passed as a pure string
Whereas the GeoSet and Surface seems to need the " ` " (forward quote) symbol building into the string
for it to function within the CreateFormula code - odd !!!
To make my Distance Measure Function available for any object to any object usage in the future I shall
a specific note regarding the need for the quote character in some circumstances
RE: Measure Distance - Point to Surface
i am using this code.
But due to some reason i m getting only 0 in as measure.
Dim length1 As Dimension
Set length1 = parameters1.CreateDimension("", "LENGTH", 0#)
RE: Measure Distance - Point to Surface
With the help above I managed to manually construct the necessary Strings to create the distance formula
I am now attempting to integrate this technique into larger "existing" macro that asks for a User Selection
of Surface to be used as the Primary Measure Object - a loop provides a means to measure a number of Points
back to this Surface
I have now have a NEW problem with constructing the String for the formula function when using a
"Isolated Surface Object" as the User Selection.
I have been using the following expression to build the String
strSurface_FunctionInputString = "`" & Surface.Parent.Parent.Name & "\" & Surface.Name & "`"
This works exactly as required for Non Isolated Surface Objects - But not for Isolated ones
I have also included a picture of my test model Spec Tree and the MsgBox returns for the Non Isolated
and Isolated Surfaces as built by the above code line
Any ideas how I can return the actual parent GeoSet of where the Isolated Surface is structured ?
Many thanks in advance
RE: Measure Distance - Point to Surface
If you select it you can get the full path using CATIA.Statusbar information.
Or you can check each oPart.Hybridbodies to see if your surface is in it.
you call
indocti discant et ament meminisse periti