Cancel
Showing results for 
Search instead for 
Did you mean: 

Putting a line on a drawing

Solution Partner Genius Solution Partner Genius
Solution Partner Genius

Hello everyone!

 

Does anybody have a clean .NET code to create 2D unassociative line on the drawing? I am a bit owerwhelmed by the amount of extra code in the journal. Man Surprised

6 REPLIES

Re: Putting a line on a drawing

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

Below find a simple VB.NET function I use.

    Function MakeLine(StartX As Double, StartY As Double, EndX As Double, EndY As Double, Color As String) As Tag
        Dim workPart As Part = theSession.Parts.Work
        Dim cCurve As Curvecollection = workPart.Curves
        Dim iColor As Integer
        
        Dim cLine As Line
        Dim pStart, pEnd As Point3d
        
        pStart.X = StartX
        pStart.Y = StartY
        pStart.Z = 0
        
        pEnd.X = EndX
        pEnd.Y = EndY
        pEnd.Z = 0
        
        cLine = cCurve.CreateLine(pStart, pEnd)
        
        theUFSession.Obj.SetFont(cLine.Tag, UFConstants.UF_OBJ_FONT_SOLID)
        
        Select Case Color.ToLower
            Case "green"
                theUFSession.Obj.SetLineWidth(cLine.Tag, UFConstants.UF_OBJ_WIDTH_THIN)
                theUFSession.Disp.AskClosestColorInDisplayedPart(UFDisp.ColorName.GreenName,iColor)
            Case "orange"
                theUFSession.Obj.SetLineWidth(cLine.Tag, UFConstants.UF_OBJ_WIDTH_NORMAL)
                theUFSession.Disp.AskClosestColorInDisplayedPart(UFDisp.ColorName.OrangeOrangeRedName,iColor)
            Case "yellow"
                theUFSession.Obj.SetLineWidth(cLine.Tag, UFConstants.UF_OBJ_WIDTH_THICK)
                theUFSession.Disp.AskClosestColorInDisplayedPart(UFDisp.ColorName.YellowName,iColor)
        End Select
        
        theUFSession.Obj.SetColor(cLine.Tag, iColor)
        
        Return cLine.Tag
    End Function

You can change the result type or remove it entirely.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.1, FBM, MRL 3.1.7 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 11.4
Development: C (ITK), .NET, Tcl/Tk Testing: NX12.0 | AWC 3.4 Preparing: NX12.0

Employees of the customers, together we are strong Smiley Wink
How to Get the Most from Your Signature in the Community
NX Customization - Best Practice Guide

Re: Putting a line on a drawing

Solution Partner Genius Solution Partner Genius
Solution Partner Genius

Thanks, I'll give it a try!

Re: Putting a line on a drawing

Solution Partner Genius Solution Partner Genius
Solution Partner Genius

And while we are at it - how do I act if I need to create a line with a given width and on a given layer? When do I assign those characteristics? Pre- or post- creation of a line itself?

Re: Putting a line on a drawing

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

The methods that create the line do not have options for layer or line width/color/font etc, so these cannot be specified at the time of creation. A line will be created on the work layer with the current object default values. This leaves you with 2 options: change the default object preferences and work layer before creating the line or changing the display settings of the object after creating the line. Of the 2 choices, I think changing it after creation is easier.

Re: Putting a line on a drawing

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

Best is to create the object and change its properties afterwards.

A line has a Layer and LineWidth property, which are very easy to change after its creation.

Best is you get hold of the NXOpen API reference to do some reading about what the line object offers.

My example function sets the lines width according to the requested color using the UF wrapper functions, if you take a closer look.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.1, FBM, MRL 3.1.7 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 11.4
Development: C (ITK), .NET, Tcl/Tk Testing: NX12.0 | AWC 3.4 Preparing: NX12.0

Employees of the customers, together we are strong Smiley Wink
How to Get the Most from Your Signature in the Community
NX Customization - Best Practice Guide

Re: Putting a line on a drawing

Solution Partner Genius Solution Partner Genius
Solution Partner Genius

I found that alternative approach work better for me. I obtained current preferences into a buffer, changed them, created a bunch of lnes and restored preferences from a buffer.