×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Extrude color as line color

Extrude color as line color

Extrude color as line color

(OP)
Hello,
I have a little problem. I want to make macro which colors extruded bodies to line's color from which this body was created.
Let's say I have a triangle wchich I extruded. The color of extruded body is, by default, grey. The lines color is, for example, green.
How to, using macro, color extruded body to green.
I was trying code below, but msgbox(...) shows me 134 (default blue color) regardless of what lines' color I set.

CODE --> vb

Option Strict Off

Imports System
Imports NXOpen


Module NXJournal

	Sub Main

		Dim TheSession As Session = Session.GetSession()
		Dim objectArray1(0) As DisplayableObject		
		Dim workPart As Part = theSession.Parts.Work
		
		Dim TempBody As NXOpen.Body
		Dim TempFeatures() As NXOpen.Features.Feature
		Dim TFeature As NXOpen.Features.Feature
		Dim TempSection() As NXOpen.Section
		Dim Tempobj() As NXobject

		For Each TempBody In workPart.Bodies
			TempFeatures = TempBody.GetFeatures
			
			TFeature = TempFeatures(0)
			TempSection = TFeature.GetSections
			TempSection(0).GetOutputCurves(Tempobj)
			Dim line2 As Line = CType(Tempobj(3), Line)
			msgbox(line2.color)
		Next

	End Sub
	
	Public Function GetUnloadOption(ByVal dummy As String) As Integer
		GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
	End Function
End Module 

---
rootek

RE: Extrude color as line color

Before you write lots of code, please realize that you can change your preferences to use the default color rather than a specific color for solid bodies. So, if your default color is set to green, any solid bodies created will be green. If you change your default color to blue, any solid bodies created will be blue, etc.

www.nxjournaling.com

RE: Extrude color as line color

(OP)
Thanks cowski for your reply!
I'm aware of that I can change default color. But it doesn't solve my problem.
I have sketch's lines in many colors. When my sketch is finished I extrude/revolute colored lines using "color filter" tool. But after that all my bodies are grey (or any other default color). Now I want to create macro which can color my bodies to the same color as lines from which this body was created (all lines creating one extrude/revolute have same color).
Best solution for me would be to add to extrude function "use parents color" but I think that this would be extremaly hard...

---
rootek

RE: Extrude color as line color

Try this journal (not thoroughly tested):

CODE

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim theUfSession As UFSession = UFSession.GetUFSession
        If IsNothing(theSession.Parts.Work) Then
            'active part required
            Return
        End If

        Dim workPart As Part = theSession.Parts.Work
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        Const undoMarkName As String = "body color = section color"
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

        For Each tempBody As Body In workPart.Bodies

            If tempBody.IsSheetBody Then
                Continue For
            End If

            lw.WriteLine("body tag: " & tempBody.Tag.ToString)
            Dim tempFeatures() As Features.Feature = tempBody.GetFeatures
            lw.WriteLine("number of features: " & tempFeatures.Length.ToString)

            'For Each myFeature As Features.Feature In tempFeatures
            '    lw.WriteLine(myFeature.GetFeatureName)
            '    lw.WriteLine("")
            'Next

            Dim tempSections() As Section = tempFeatures(0).GetSections
            lw.WriteLine("number of sections in first feature: " & tempSections.Length.ToString)

            If tempSections.Length > 0 Then

                'get color of first element in section
                Dim startElement As ICurve
                Dim startPt As Point3d
                Dim direction As Vector3d

                tempSections(0).GetStartAndDirection(startElement, startPt, direction)

                lw.WriteLine("start element of first section: " & startElement.GetType.ToString)
                Dim tempCurve As Curve = CType(startElement, Curve)
                lw.WriteLine("color index: " & tempCurve.Color.ToString)

                Dim colorName As String
                Dim clrVal(2) As Double
                theUfSession.Disp.AskColor(tempCurve.Color, UFConstants.UF_DISP_rgb_model, colorName, clrVal)
                lw.WriteLine("color name: " & colorName)

                tempBody.Color = tempCurve.Color
                tempBody.RedisplayObject()

            Else
                lw.WriteLine("no section")

            End If

            lw.WriteLine("")

        Next

        lw.Close()

    End Sub


    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

        '----Other unload options-------
        'Unloads the image immediately after execution within NX
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

        'Unloads the image explicitly, via an unload dialog
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly
        '-------------------------------

    End Function

End Module 

www.nxjournaling.com

RE: Extrude color as line color

(OP)
It works great!
Thank You cowski, you're the best!

---
rootek

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources