×
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

create groups by color journal
2

create groups by color journal

create groups by color journal

(OP)
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!

RE: create groups by color journal

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

RE: create groups by color journal

2
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 

RE: create groups by color journal

(OP)
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!!!

RE: create groups by color journal

It's probably possible. I'll look into it.

RE: create groups by color journal

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.

RE: create groups by color journal

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)

RE: create groups by color journal

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.

RE: create groups by color journal

Not sure which version on NX you are running. There is a FeatureGroup class in NX 8.5. It lets you add members to the group.

Suresh
www.technisites.com.au

RE: create groups by color journal

@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.

RE: create groups by color journal

Yes, strangely there is no builder. But you can create the group with ufs.Modl.CreateSetOfFeature(..) and then use this class to add or remove members.

Suresh
www.technisites.com.au

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