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.
---
rootek
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
www.nxjournaling.com
RE: Extrude color as line color
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
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 Modulewww.nxjournaling.com
RE: Extrude color as line color
Thank You cowski, you're the best!
---
rootek