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!

Interactive Indication of a 3D point on curve or on surface

Status
Not open for further replies.

Maddy02

Mechanical
Feb 14, 2013
114
IN
Hi,

I'm working on to get a user input as follows.

User has to indicate two points to measure distance (on curve, or on surface/face) inside a part document.
I'm in a bit of dilemma with the API's in documentation.
Could somebody guide me on this or perhaps with a code to achieve the same.

Taking this as an input i need to measure the distance between two points on a curve.

Regards,
Maddy

Regards,
Maddy

The willingness to share knowledge does not make one charitable; it makes one self-reliant to know more.
Modified - Courtesy of Robert Brault
 
Replies continue below

Recommended for you

Show us your code, we'll try to explain how to make it work.

Eric N.
indocti discant et ament meminisse periti
 
Code:
Sub CATMain()
	Dim oDoc As Document
	Set oDoc = CATIA.ActiveDocument
	
	Dim oSel As Selection
	Set oSel = oDoc.Selection
	
	Dim oPart As Product
	Set oPart = oDoc.Part
	
	Dim oHybridBodies As HybridBodies
	Set oHybridBodies = oPart.HybridBodies
	
	Dim oHybridBody As HybridBody
	Set oHybridBody = oHybridBodies.Add()
	oHybridBody.Name = "User Selected point"
	
	oPart.InWorkObject = oHybridBody	
	oPart.Update
	
	Dim oHSF As HybridShapeFactory
	Set oHSF = oPart.HybridShapeFactory
	
	Dim oInputObjectType()
	Dim iStatus As Integer	
	ReDim oInputObjectType(1)
	oInputObjectType(0)="TriDimFeatEdge"
	oInputObjectType(1)="BiDimFeatEdge"
	iStatus = oSel.SelectElement2(oInputObjectType,"Select an edge ",FALSE)
	
	If (iStatus = "Cancel" Or iStatus = "Undo" Or iStatus = "Redo") then Exit Sub
	Dim oEdgeOrCurveSelected 
	Set oEdgeOrCurveSelected = oSel.Item(1).Value
	
	'Dim s
	's = TypeName(oEdgeOrCurveSelected) & vblf & vblf
	's = s & TypeName(oEdgeOrCurveSelected.Parent) & vblf & vblf 
	's = s & oEdgeOrCurveSelected.Parent.Name & vblf & vblf
	's = s & TypeName(oEdgeOrCurveSelected.Parent.Parent) & vblf & vblf
	's = s & TypeName(oEdgeOrCurveSelected.Parent.Parent.Parent) & vblf & vblf
	's = s & TypeName(oEdgeOrCurveSelected.Parent.Parent.Parent.Parent) & vblf & vblf
	's = s & TypeName(oEdgeOrCurveSelected.Parent.Parent.Parent.Parent.Parent) & vblf & vblf
	's = s & TypeName(oEdgeOrCurveSelected.Parent.Parent.Parent.Parent.Parent.Parent) & vblf	
	'MsgBox s
	iStatus = MsgBox("Please Select Point 1",VbOkOnly,"Point 1")
	If iStatus = vbCancel Then Exit Sub
	' Following has been taken from documentation
	' ****************************
	' See also: Selection.IndicateOrSelectElement3D which can, in particular, 
	'enable indication and not selection (positionning the iFilterType parameter 
	'to an empty string), whichs enables to subscribe to mouse move events, 
	'positionning the iTriggeringOnPreSelection to true.
	' ****************************
	Dim HybridShapeFactory
	Dim InputObjectType(0)
	Dim WindowLocation2D(1)
	Dim WindowLocation3D(2)
	Dim TempPointHasBeenCreatedAtLeastOnce
	Dim ObjectSelected
	Dim ExistingPoint
	Dim PlaneReference
	
	
	ReDim WindowLocation2D(1),WindowLocation3D(2)
	InputObjectType(0) = ""
	Set HybridShapeFactory = Part.HybridShapeFactory : 
	Set Body = Part.Bodies.Item("PartBody")
	'Set HybridShapePlane = Body.HybridShapes.Item("Plane.1")
	Set HybridShapePlane = Part.OriginElements.PlaneXY 
	Set PlaneReference = Part.CreateReferenceFromObject(HybridShapePlane)

	' Empty string - through filter array
	iStatus = oSel.IndicateOrSelectElement3D(HybridShapePlane,"select a point or click to locate the point", _ 
                                            InputObjectType,false,false,true, _ 
                                            ObjectSelected,WindowLocation2D,WindowLocation3D)
          ' Not working
	' Empty string - Direct
	iStatus = oSel.IndicateOrSelectElement3D(HybridShapePlane,"select a point or click to locate the point", _ 
                                            "",false,false,true, _ 
                                            ObjectSelected,WindowLocation2D,WindowLocation3D)
                    ' Not working
	' This selects the existing point.
	InputObjectType(0) = "Point"
	iStatus = oSel.SelectElement3(InputObjectType,"Select points", _
                                 true,CATMultiSelTriggWhenSelPerf,false)

	

End Sub
What i want is similar to Document.Indicate2D(" Click to indicate Point", oInputObjectType) which gives me back coordinates of the indicated 2D point .
Same way, is it Possible to get 3D Coordinates i.e X,Y,Z. Indicated 3D option does mention about the same i suppose.

Can you guide me on this.

Regards,
Maddy

Regards,
Maddy

The willingness to share knowledge does not make one charitable; it makes one self-reliant to know more.
Modified - Courtesy of Robert Brault
 
Is not quite you want but it can help you (I believe from here you can get also the coordinates).

Code:
Sub CATMain ()

   Dim Was1(0)
   Was1(0) = "Point"
   Dim UserSel As Selection
   Set UserSel= CATIA.ActiveDocument.Selection
   UserSel.Clear
   Dim E As CATBSTR
   E = UserSel.SelectElement2(Was1, "Point", False)
   If E = "Normal" Then
   FirstPoint = UserSel.Item(1).Value.Name
      MsgBox FirstPoint
   Else
      MsgBox ("Abort")
   End If
   UserSel.Clear
    ' --------------------------------------------  
      Dim Was2(0)
   Was2(0) = "Point"
    Dim UserSel2 As Selection
   Set UserSel2= CATIA.ActiveDocument.Selection
   UserSel2.Clear
   Dim F As CATBSTR
   F = UserSel2.SelectElement2(Was2, "Point", False)
   If F = "Normal" Then
   SecondPoint = UserSel2.Item(1).Value.Name
      MsgBox SecondPoint
   Else
      MsgBox ("Abort")
   End If
   UserSel2.Clear
 ' --------------------------------------------  
   
Dim documents1 As Documents
Set documents1 = CATIA.Documents

Dim pDocument1 As PartDocument
Set pDocument1 = CATIA.ActiveDocument

Dim part1 As Part
Set part1 = pDocument1.Part

Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies

Dim reference1 As Reference
Dim hybridBody1 As HybridBody
Set hybridBody1 = hybridBodies1.Item(1)
Set hybridShapes1 = hybridBody1.HybridShapes
Set reference1 = hybridShapes1.Item(FirstPoint)
MsgBox ("ref1=" & reference1.Name)

Dim reference2 As Reference
Set reference2 = hybridShapes1.Item(SecondPoint)
MsgBox ("ref2=" & reference2.Name)

Dim TheSPAWorkbench As Workbench
Set TheSPAWorkbench = CATIA.ActiveDocument.GetWorkbench("SPAWorkbench")
Dim TheMeasurable As Measurable
Set TheMeasurable = TheSPAWorkbench.GetMeasurable(reference1)
Dim MinimumDistance As Double
MinimumDistance = TheMeasurable.GetMinimumDistance(reference2)
MsgBox MinimumDistance

End Sub

Regards
Fernando

 
Hi,

@ferdo

With reference to your post on below thread you have about CreateReferenceFromBRepName
Dim reference1 As Reference
' CreateReferenceFromBRepName( CATBSTR iLabel, CATIABase iObjectContext) As CATIAReference
Set reference1 = part1.CreateReferenceFromBRepName("RSur:(Face:(Brp:(AxisSystem.1;1);None:();Cf11:());WithPermanentBody;WithoutBuildError;WithSelectingFeatureSupport;MFBRepVersion_CXR15)", axisSystem1)
[ol ] about Reference1
[li]i would like to know how, above is achieved (Underline One). (recorded i suppose)[/li]
[li]Is it possible to get this from selected edge of pad or a surface. (Could you give an example for clarity)[/li]
[li]i would like to create a point on the selected edge[/li]
[ol a]
[li]user has to indicate the point interactively.
i.e he can indicate a point by clicking on selected curve apart from existing point / vertex[/li]
[/ol]

[/ol]
need your assistance to get the code right which asks and grab the indicated point (similar to indicate2D)


Regards,
Maddy

The willingness to share knowledge does not make one charitable; it makes one self-reliant to know more.
Modified - Courtesy of Robert Brault
 
Hi
@ ferdo,
Thanks for reply.
If the filter type is point / vertex then i don't have any issue in getting the coordinates.
But i'm working on is exactly similar to Indicate2D option where user clicks on drawing which gives back X,Y of point.
Same way here he has to click on curve he selected earlier. This is where i got stuck.

Documentation for Indicate3D mentions that
Selection.IndicateOrSelectElement3D which can, in particular,
enable indication and not selection (positioning the iFilterType parameter to an empty string), whichs enables to subscribe to mouse move events, positioning the iTriggeringOnPreSelection to true.

Regards,
Maddy

The willingness to share knowledge does not make one charitable; it makes one self-reliant to know more.
Modified - Courtesy of Robert Brault
 
Google IndicateOrSelectElement3D and found this on cad.de forum. it does not work but with small change then it works: [bigsmile]



Code:
Sub main()

Dim Ergebnis As String
Dim XZ(1), XYZ(2) ' As Double  <== modification 1
Dim SelInd As Boolean
Dim Filter(0)
Dim Selektion 'As Variant <== modification 2

Dim coord(2) As Single

Set partDocument1 = CATIA.ActiveDocument
Set part1 = partDocument1.Part
Set hybridBodies1 = part1.HybridBodies
Set hybridBody1 = hybridBodies1.Item("Geometrical Set.1")
Set hybridShapes1 = hybridBody1.HybridShapes
Set hybridShapePlaneOffset1 = hybridShapes1.Item("Plane.1")

Filter(0) = "AnyObject"
Set Selektion = CATIA.ActiveDocument.Selection

Selektion.Clear
Ergebnis = Selektion.IndicateOrSelectElement3D(hybridShapePlaneOffset1, "Auswahl", Filter, False, False, False, False, XZ, XYZ)
If Selektion.Count <> 0 Then
Selektion.Item(1).GetCoordinates coord
MsgBox (coord(0) & "  " & coord(2))

Else
MsgBox ("X-eben= " & XZ(1) & ", Z-eben= " & XZ(0) & Space(15) & "X-3D= " & XYZ(0) & ", Y-3D= " & XYZ(1) & ", Z-3D= " & XYZ(2))
End If

End Sub

Eric N.
indocti discant et ament meminisse periti
 
if you want to code a point on curve function, you can

get the user to select the curve

indicate point with IndicateOrSelectElement3D and filter set to MonoDim (for curve)
get the 3D coordonate of the result
create 3d point with coordonate (it will be on plane from IndicateOrSelectElement3D and not on curve)
get direction normal to screen
project point to curve using direction
(if projection fail, user indicate on wrong curve)
split curve with point
compare length of split / length of curve

finaly build your point on curve using the ratio

delete all temp element: point(by coordonates), projection point, split.

I could not find a way to launch the command "point" with restriction to "on curve"

CATIA.StartCommand "Point" works but not exactly what you looking for.

Eric N.
indocti discant et ament meminisse periti
 
Hi,

@Eric

Thanks for reply,
Will try to work on the points your said.
By taking only one point into consideration i.e. enable indication and not selection (positioning the iFilterType parameter to an empty string) i was working on to achieve as desired.

@ferdo or @Eric
Could you elaborate on
@ferdo

With reference to your post on below thread you have about CreateReferenceFromBRepName
Dim reference1 As Reference
' CreateReferenceFromBRepName( CATBSTR iLabel, CATIABase iObjectContext) As CATIAReference
Set reference1 = part1.CreateReferenceFromBRepName("RSur:(Face:(Brp:(AxisSystem.1;1);None:();Cf11:());WithPermanentBody;WithoutBuildError;WithSelectingFeatureSupport;MFBRepVersion_CXR15)", axisSystem1)

about Reference1
i would like to know how, above is achieved (Underline One). (recorded i suppose)
Is it possible to get this from selected edge of pad or a surface. (Could you give an example for clarity)



Regards,
Maddy

The willingness to share knowledge does not make one charitable; it makes one self-reliant to know more.
Modified - Courtesy of Robert Brault
 
@ Maddy

AxisSystem.1;1 is the xoy plane of your CATPart origin and AxisSystem.1;3 is the xoz plane. They are created by default when you have the option ticked to insert an axis system when you start a new CATPart.

About references...I believe this link it will help you a little bit .

And bellow is how you can add a point on a curve (this is a specific case but you can get an idea how to do it in your case).

By the way, I'm really curios to see the code at the end.

Code:
' ==============================================================
' Purpose: Creation of a point in the midlle of a Circle (or Circle Edge)
' Usage:   1 - A CATPart must be active and should have at least one hole feature to be able to select an edge (or a circle wireframe)
'          2 - Run macro 
' Author: ferdo (Disclaimer: You use this code at your own risk) 
' ===============================================================

Sub CATMain()

Dim productDocument1 As ProductDocument
Set productDocument1 = CATIA.ActiveDocument

Dim documents1 As Documents
Set documents1 = CATIA.Documents

Dim partDocument1 As PartDocument
Set partDocument1 = documents1.Item(1)

Dim part1 As Part
Set oPart = CATIA.ActiveDocument.Part

Dim reference1 As Reference
Set oHSF = oPart.HybridShapeFactory

msgbox "Select Circle (or Circle Edge)"

Dim InputObject(0)
InputObject(0) = "Edge"

Set oCentre = CATIA.ActiveDocument.Selection
Status = oCentre.SelectElement2(InputObject, "Select Circle", False)

Set oTemp = oCentre.Item(1)
Set oRef = oTemp.Reference
Set oPoint = oHSF.AddNewPointCenter(oRef)
Set oHB = oPart.HybridBodies.Add()
oPoint.Compute
oHB.AppendHybridShape oPoint

End Sub

Regards
Fernando

 
Hi,
@Ferdo

Thanks for your code.

I'll upload the code once completed.

As of now i'm able to get the references of a selected edge (from Graphical Window) and pass on to create point
but yet to get the IndicateOrSelectElement3D option to work out.
Though this option is working results are not as per expected.



Regards,
Maddy

The willingness to share knowledge does not make one charitable; it makes one self-reliant to know more.
Modified - Courtesy of Robert Brault
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top