PutLineSegmentData is not semmingly working

PutLineSegmentData is not semmingly working

Anonymous
Not applicable
505 Views
3 Replies
Message 1 of 4

PutLineSegmentData is not semmingly working

Anonymous
Not applicable

The second sub (NormalTest) below creates the ClientGraphic and the first sub (NormalTest_MagnitdureChange) attempts to lengthen the associated LineSegment in the Y direction so you must select a face along the XZ plane so the before running the second sub so that the line segment runs only in the Y direction.  That said, when I run the first sub its 2 MsgBox display the before and after coordinates which does display the ending points Y coordinate doubled but graphically there's no change.  If you run the first sub again you'll get the same results meaning the double length did not take the first time this sub was run even though oLineSegment.EndPoint.Y has changed according to the after MsgBox from the previous executing of the first sub.  Am I doing something wrong?  If not then why

 

 

Public Sub NormalTest_MagnitudeChange()
    Dim oPartDocument As PartDocument
    Dim oFace As Face
    Dim oClientGraphics As ClientGraphics
    Dim oSurfaceEvaluator As SurfaceEvaluator
    Dim adPoint(2) As Double
    Dim adParams(1) As Double
    Dim adGuessParams() As Double
    Dim adMaxDeviations() As Double
    Dim aoSolutionNatureEnum() As SolutionNatureEnum
    Dim adNormals(2) As Double
    Dim oVector_Normal As Vector
    Dim oLineSegment As LineSegment
    Dim oPoint_Normal As Point
    Dim oGraphicsNode_CurveGraphics As GraphicsNode
    Dim oCurveGraphics As CurveGraphics
    Dim adStPt(2) As Double
    Dim adEndPt(2) As Double
    
    Set oPartDocument = ThisApplication.ActiveDocument
    
    On Error Resume Next
    Set oClientGraphics = oPartDocument.ComponentDefinition.ClientGraphicsCollection. _
        Item("NormalTest")
    If Err.Number <> 0 Then
        MsgBox "You must run NormalTest first."
        Exit Sub
    End If
    
    On Error GoTo 0
        
    Set oGraphicsNode_CurveGraphics = oClientGraphics.Item(1)
    Set oCurveGraphics = oGraphicsNode_CurveGraphics.Item(1)
    Set oLineSegment = oCurveGraphics.Curve
    MsgBox _
        "Start pt: " & oLineSegment.StartPoint.X & ", " & oLineSegment.StartPoint.Y & _
            ", " & oLineSegment.StartPoint.Z & vbCr & _
        "End pt: " & oLineSegment.EndPoint.X & ", " & oLineSegment.EndPoint.Y & _
            ", " & oLineSegment.EndPoint.Z
    oLineSegment.GetLineSegmentData adStPt, adEndPt
    adEndPt(1) = adEndPt(1) * 2     'Double the length in the Y direction
    oLineSegment.PutLineSegmentData adStPt, adEndPt
    ThisApplication.ActiveView.Update   ' Update the view.
    MsgBox _
        "Start pt: " & oLineSegment.StartPoint.X & ", " & oLineSegment.StartPoint.Y & _
            ", " & oLineSegment.StartPoint.Z & vbCr & _
        "End pt: " & oLineSegment.EndPoint.X & ", " & oLineSegment.EndPoint.Y & _
            ", " & oLineSegment.EndPoint.Z
End Sub

 

Public Sub NormalTest()
    Dim oPartDocument As PartDocument
    Dim oFace As Face
    Dim oClientGraphics As ClientGraphics
    Dim oSurfaceEvaluator As SurfaceEvaluator
    Dim adPoint(2) As Double
    Dim adParams(1) As Double
    Dim adGuessParams() As Double
    Dim adMaxDeviations() As Double
    Dim aoSolutionNatureEnum() As SolutionNatureEnum
    Dim adNormals(2) As Double
    Dim oVector_Normal As Vector
    Dim oLineSegment As LineSegment
    Dim oPoint_Normal As Point
    Dim oGraphicsNode As GraphicsNode
    
     Set oPartDocument = ThisApplication.ActiveDocument
    
    On Error Resume Next
    Set oFace = oPartDocument.SelectSet.Item(1)
    If Err Then
        MsgBox "A face must be selected."        ' Delete any existing client graphics.
        oPartDocument.ComponentDefinition.ClientGraphicsCollection. _
            Item("NormalTest").Delete
        Exit Sub
    End If

    Set oClientGraphics = oPartDocument.ComponentDefinition.ClientGraphicsCollection. _
        Item("NormalTest")
    If Err.Number = 0 Then
        oClientGraphics.Delete
        ThisApplication.ActiveView.Update
    End If
    On Error GoTo 0
    
    Set oClientGraphics = oPartDocument.ComponentDefinition. _
        ClientGraphicsCollection.Add("NormalTest")
    
     Set oSurfaceEvaluator = oFace.Evaluator
    oFace.PointOnFace.GetPointData adPoint
    oSurfaceEvaluator.GetParamAtPoint adPoint, adGuessParams, adMaxDeviations, _
        adParams, aoSolutionNatureEnum
    oSurfaceEvaluator.GetNormal adParams, adNormals
    
     Set oVector_Normal = ThisApplication.TransientGeometry.CreateVector( _
        adNormals(0), adNormals(1), adNormals(2))
    oVector_Normal.ScaleBy 2.54  'convert 1 cm to 1 inch
    
    Set oPoint_Normal = oFace.PointOnFace
    oPoint_Normal.TranslateBy oVector_Normal
    Set oLineSegment = ThisApplication.TransientGeometry.CreateLineSegment( _
        oFace.PointOnFace, oPoint_Normal)
    
    Set oGraphicsNode = oClientGraphics.AddNode(1)
    oGraphicsNode.AddCurveGraphics oLineSegment
    
    ThisApplication.ActiveView.Update
End Sub

 

0 Likes
Accepted solutions (1)
506 Views
3 Replies
Replies (3)
Message 2 of 4

ekinsb
Alumni
Alumni

When you use the line

 

    Set oLineSegment = oCurveGraphics.Curve

 

The LineSegment you get back is not associated with the CurveGraphics objects.  It's essentially a snapshot of the curve.  After you've modified the line you just need to assign it back to the CurveGraphics object to update the graphics.

 

    oCurveGraphics.Curve = oLineSegment

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 3 of 4

Anonymous
Not applicable
Thanks Brian, that did the trick. Perhaps you or someone else can help make my app more efficient if what I desire exists in ClientGraphics. Is there a way of simply modify a number to change the length of a line segments from the starting point? I'm guessing no. I'm guess I have to recalculate new end points (which is why I started this thread). I'm going to be creating hundreds of individual line segments (no association between segments) perpendicular to the selected surface of a solid (commonly for a cylinder or a portion of a torus). Each line segment will start on the surface and run through one of the supplied point. The length of the segment is obviously the distance between the calculate point on the surface that's perpendicular from the supplied point to the surface however I'm going to have a multiplier called magnitude that will control the final length (for magnified visualization purposes).
0 Likes
Message 4 of 4

ekinsb
Alumni
Alumni
Accepted solution

Attached is a sample that draws lines over the entire area of a selected face showing the normal of the face at that point.  There is a variable called "Scale" that can be set that determine the length of the lines.  Hopefully this will help.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes