Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

create groups by color journal 2

Status
Not open for further replies.

MR76

Automotive
Dec 4, 2015
10
Hi guys,

I have to work with extremely big step files, around 450 mB (usually molds), which have hundreds of bodies. All of them in layer 1… so I can’t filter them by layer, but luckily I do can filter them by color. My intention is to make groups by color with bodies, so then I can work with each group to extract “center lines” in cylinders (each color represents different pipe´s circuit, that’s why I want them separately). My idea is to group them all, and then hide them or deactivate them (it will depend on group type… feature ones or simple groups)
Does anyone knows or have a journal that can do this “group by color” automatically?
I can do it manually, but it takes hours, because each time I filter out and create a group it takes between 10 to 15 minutes (and there are plenty of them).
And after that I have to extract curves…
Another way could be “create components by color”, so once colored bodies belong to each component, I could work on them individually.

Any help will be really helpful. Because I have been working this manually, but I think this should be done faster.

THANKS IN ADVANCE!
 
Replies continue below

Recommended for you

If you always have the same set of colors, have you tried recording a journal for a single color? You should be able to edit that and copy/paste/edit the code for each color.

If there are a lot of colors, then for sure you need a more advanced program that cycles through everything.

Mark Rief
NX CAM Customer Success
Siemens PLM Software
 
Here's some code that might get you started:

Code:
Option Infer On
Imports Snap, Snap.Create

Public Class MyProgram

   Public Shared Sub Main()

      Dim workPart As Snap.NX.Part = Snap.Globals.WorkPart

      Dim groupArray(216) As NXOpen.Group

      For index = 1 To 216
         Dim groupName As String = "GROUP_" & index.ToString
         groupArray(index) = NewGroup(groupName)
      Next

      For Each obj As Snap.NX.NXObject In workPart.Objects
         If obj.HasDisplayProperties
            Dim colorIndex As Integer = Snap.Color.ColorIndex(obj.Color)
            AddToGroup(groupArray(colorIndex), obj)
         End If
      Next

   End Sub

   Public Shared Function NewGroup(groupName As String) As NXOpen.Group

      Dim theSession = NXOpen.Session.GetSession
      Dim workPart = theSession.Parts.Work

      Dim builder = workPart.CreateGatewayGroupBuilder(Nothing)

      builder.ActivegroupOption = True
      builder.ActionType = 0
      builder.GroupDisplayProperties = False
      builder.GroupName = groupName

      Dim group1 As NXOpen.Group = builder.Commit()
      builder.Destroy()

      Return group1

   End Function

   Public Shared Sub AddToGroup(group As NXOpen.Group, obj As NXOpen.TaggedObject)

      Dim theSession = NXOpen.Session.GetSession
      Dim workPart = theSession.Parts.Work

      Dim builder = workPart.CreateGatewayGroupBuilder(group)

      builder.ActivegroupOption = True
      builder.ActionType = 4

      Dim added As Boolean = builder.ObjectsInGroup.Add(obj)

      builder.Commit()

   End Sub

End Class
 
WOW! IT WORKS!!

JUST IN CASE... IS IT POSSIBLE THIS JOURNAL CREATES FEATURE GROUPS INSTEAD OF SIMPLE GROUPS?

IF YOU TELL ME HOW TO EDIT IT I COULD TRY, DONT WANT YOU TO THINK I DONT WANT TO WORK ON IT.

THANK YOU AGAIN!!!
 
It's probably possible. I'll look into it.
 
I spoke too soon.

I looked in all the usual and obvious places, and I can't find the function to create a Feature Group. If you can find the function, you need to plug it into the NewGroup and AddToGroup functions in my code.

Sorry I can't be of more help.

Another option you might try -- organising your objects by layer might work better than using groups.
 
Not sure if this will work in Snap.


' -----------------------------------------------------------------------------------------
' Creating Feature Group
' -----------------------------------------------------------------------------------------
myTagArray(0) = MyTag
Dim fGroup As Tag = Tag.Null
ufs.Modl.CreateSetOfFeature("MILL_ON", myTagArray, 1, 0, fGroup)
 
Thank you kr7530.

If a "set of features" is the same thing as a "feature group", then this should work. However, there does not seem to be any function for adding an object to a "feature group". So you'll have to gather together all the features of a given color in some temporary data structure, and create the group after the gathering stage is finished.

Regarding whether or not it will work "in SNAP". There's really no such thing as "in SNAP". SNAP isn't a language like GRIP or KF, it's just a library of functions. You can call SNAP functions (along with functions from any other library you choose) in any VB program.
 
@ufsure -- yes, I saw the FaetureGroup class, and I saw the AddMembers method. But I haven't found a function to create a FeatureGroup. There does not seem to be a FeatureGroupBuilder class.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor