"Highlight" specific solid bodies in a part File

"Highlight" specific solid bodies in a part File

C_Haines_ENG
Collaborator Collaborator
529 Views
8 Replies
Message 1 of 9

"Highlight" specific solid bodies in a part File

C_Haines_ENG
Collaborator
Collaborator

I can almost garuentee this isnt possible, but im essentially automating our descriptions but for that you need to enter what kind of panel youre working with. Essentially, when you highlight over a solidbody you get this look:

chainesL5H3G_0-1668023259263.png

Is it possible to replicate this with ilogic?

 

My program will cycle through each solid body, and ask for the panel name.

0 Likes
Accepted solutions (1)
530 Views
8 Replies
Replies (8)
Message 2 of 9

JelteDeJong
Mentor
Mentor
Accepted solution

You can try something like this:

Dim oTr As TransientObjects = ThisApplication.TransientObjects
Dim doc As AssemblyDocument = ThisDoc.Document

For Each occ As ComponentOccurrence In doc.ComponentDefinition.Occurrences

	Dim topFace As HighlightSet = doc.HighlightSets.Add()
	topFace.Color = oTr.CreateColor(0, 255, 0, 0.1)
	topFace.Clear()
	topFace.AddItem(occ)

	Dim newName = InputBox("Plz give a new name", "Name PLZ", occ._DisplayName)

	iProperties.Value("Project", "Description") = newName
	

	topFace.Remove(occ)
Next

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 9

C_Haines_ENG
Collaborator
Collaborator

I need it to work on part files with solid bodies, yours seems to only work with assembly documents.

0 Likes
Message 4 of 9

J-Camper
Advisor
Advisor

@C_Haines_ENG,

 

Here it is for Solid bodies in a Part Environment:

 

Dim pDoc As PartDocument = TryCast(ThisApplication.ActiveDocument, PartDocument)
If IsNothing(pDoc) Then Logger.Debug("Active Document is not: " & CType(pDoc.Type, ObjectTypeEnum).ToString)

Dim selectThis As HighlightSet = pDoc.CreateHighlightSet

For Each oSolid As SurfaceBody In pDoc.ComponentDefinition.SurfaceBodies
	selectThis.AddItem(oSolid)
	MessageBox.Show("Solid Selected", "Pause for Action")
	selectThis.Clear
Next

 

Let me know if you have any questions

0 Likes
Message 5 of 9

JelteDeJong
Mentor
Mentor

oke try this:

Dim oTr As TransientObjects = ThisApplication.TransientObjects
Dim doc As PartDocument = ThisDoc.Document

For Each body As SurfaceBody In doc.ComponentDefinition.SurfaceBodies

	Dim topFace As HighlightSet = doc.HighlightSets.Add()
	topFace.Color = oTr.CreateColor(0, 255, 0, 0.1)
	topFace.Clear()
	topFace.AddItem(body)

	Dim newName = InputBox("Plz give a new name", "Name PLZ", body.Name)

	body.Name = newName

	topFace.Remove(body)
Next

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 6 of 9

C_Haines_ENG
Collaborator
Collaborator

**** you cant see the highlighted panel through objects, is there a hide others command?

0 Likes
Message 7 of 9

JelteDeJong
Mentor
Mentor

Give it a try like this:

Dim oTr As TransientObjects = ThisApplication.TransientObjects
Dim doc As PartDocument = ThisDoc.Document

For Each body As SurfaceBody In doc.ComponentDefinition.SurfaceBodies
    Dim color As Color = oTr.CreateColor(0, 255, 0, 1)

    Dim highlightSet As HighlightSet = doc.HighlightSets.Add()
    highlightSet.Color = color

    For Each edge As Edge In body.Edges
        highlightSet.AddItem(Edge)
    Next

    body.Name = InputBox("Plz give a new name", "Name PLZ", body.Name)

    highlightSet.Remove(body)
Next

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 8 of 9

J-Camper
Advisor
Advisor

@C_Haines_ENG,

 

Here is an example where I hide all other bodies.  Not sure if you still need them to be highlighted at that point, but I left it in:

 

Sub Main

	Dim pDoc As PartDocument = TryCast(ThisApplication.ActiveDocument, PartDocument)
	If IsNothing(pDoc) Then Logger.Debug("Active Document is not: " & CType(pDoc.Type, ObjectTypeEnum).ToString)

	Dim selectThis As HighlightSet = pDoc.CreateHighlightSet
	Dim AllBodies As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection

	For Each sb As SurfaceBody In pDoc.ComponentDefinition.SurfaceBodies
		AllBodies.Add(sb)
	Next

	For Each oSolid As SurfaceBody In pDoc.ComponentDefinition.SurfaceBodies
		AllBodies.RemoveByObject(oSolid)
		Call HideAll(AllBodies, False)
		selectThis.AddItem(oSolid)
		MessageBox.Show("Solid Selected", "Pause for Action")
		selectThis.Clear
		Call HideAll(AllBodies, True)
		AllBodies.Add(oSolid)
	Next

End Sub

Sub HideAll(BodyCol As ObjectCollection, Visibility As Boolean)
	
	For Each sb As SurfaceBody In BodyCol
		sb.Visible = Visibility
	Next
	
End Sub

 

The only way to use the UI "HideOthers" command is through ControlDefinitions, which I'm not a fan of, but it could look like this:

 

Sub Main

	Dim pDoc As PartDocument = TryCast(ThisApplication.ActiveDocument, PartDocument)
	If IsNothing(pDoc) Then Logger.Debug("Active Document is not: " & CType(pDoc.Type, ObjectTypeEnum).ToString)

	Dim selectThis As HighlightSet = pDoc.CreateHighlightSet
	Dim selSet As SelectSet = pDoc.SelectSet
	
	Dim HideOthers As ControlDefinition = ThisApplication.CommandManager.ControlDefinitions.Item("HideOtherBodiesCtxCmd")
	Dim ShowAll As ControlDefinition = ThisApplication.CommandManager.ControlDefinitions.Item("ShowAllBodiesCtxCmd")

	For Each oSolid As SurfaceBody In pDoc.ComponentDefinition.SurfaceBodies
		selSet.Select(oSolid)
		HideOthers.Execute
		selectThis.AddItem(oSolid)
		MessageBox.Show("Solid Selected", "Pause for Action")
		selectThis.Clear
		selSet.Remove(oSolid)
	Next
	
	ShowAll.Execute

End Sub

 

Let me know if you have any questions

Message 9 of 9

C_Haines_ENG
Collaborator
Collaborator

This works fantastic! Thank you!

0 Likes