Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Inventor API - Highlight Selected Faces

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Khoa_NguyenDang
2426 Views, 5 Replies

Inventor API - Highlight Selected Faces

Khoa_NguyenDang
Advocate
Advocate

Hi all, does anyone know the code to highlight face like in this picture

If you know any solution, please help me

Thank you so much

Khoa_NguyenDang_0-1608139259621.png

 

0 Likes

Inventor API - Highlight Selected Faces

Hi all, does anyone know the code to highlight face like in this picture

If you know any solution, please help me

Thank you so much

Khoa_NguyenDang_0-1608139259621.png

 

Labels (1)
5 REPLIES 5
Message 2 of 6

WCrihfield
Mentor
Mentor
Accepted solution

Here is a very simple iLogic rule that should do what you want:

Dim oDoc As Document = ThisDoc.Document
Dim oSS As SelectSet = oDoc.SelectSet
oSS.Clear
Dim oHSet As HighlightSet = oDoc.CreateHighlightSet()
Dim oFace As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select a part face to highlight.")
oSS.Select(oFace)
oHSet.AddItem(oFace)

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.

If you have time, please... Vote For My IDEAS :light_bulb:and Explore My CONTRIBUTIONS

Inventor 2021 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Here is a very simple iLogic rule that should do what you want:

Dim oDoc As Document = ThisDoc.Document
Dim oSS As SelectSet = oDoc.SelectSet
oSS.Clear
Dim oHSet As HighlightSet = oDoc.CreateHighlightSet()
Dim oFace As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select a part face to highlight.")
oSS.Select(oFace)
oHSet.AddItem(oFace)

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.

If you have time, please... Vote For My IDEAS :light_bulb:and Explore My CONTRIBUTIONS

Inventor 2021 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 6

WCrihfield
Mentor
Mentor
Accepted solution

Or if you don't want to manually select the face, there are a couple other options.

Option one:  you could simply specify the face by its index number on the solid body (if you know which one it was).

Option two:  assign a name to the face in the model, then identify and get the face by that name using the NamedEntities technique.

Here's an example of Option one:

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kPartDocumentObject Then
	MsgBox("A Part Document must be active for this rule (" & iLogicVb.RuleName & ") to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
	Exit Sub
End If
Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim oSS As SelectSet = oPDoc.SelectSet
oSS.Clear
Dim oHSet As HighlightSet = oPDoc.CreateHighlightSet()
Dim oBody As SurfaceBody = oPDef.SurfaceBodies.Item(1)
Dim oFace As Face = oBody.Faces.Item(1)
oSS.Select(oFace)
oHSet.AddItem(oFace)

And here is an example of Option two:

(Keep in mind this won't work unless you have assigned that face a name in your model, and the name matches the name specified within the code.)

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kPartDocumentObject Then
	MsgBox("A Part Document must be active for this rule (" & iLogicVb.RuleName & ") to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
	Exit Sub
End If
Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
Dim oNE As NamedEntities = iLogicVb.Automation.GetNamedEntities(oPDoc)
Dim oSS As SelectSet = oPDoc.SelectSet
oSS.Clear
Dim oHSet As HighlightSet = oPDoc.CreateHighlightSet()
Dim oFace As Face = oNE.TryGetEntity("Top Face")
oSS.Select(oFace)
oHSet.AddItem(oFace)

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Or if you don't want to manually select the face, there are a couple other options.

Option one:  you could simply specify the face by its index number on the solid body (if you know which one it was).

Option two:  assign a name to the face in the model, then identify and get the face by that name using the NamedEntities technique.

Here's an example of Option one:

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kPartDocumentObject Then
	MsgBox("A Part Document must be active for this rule (" & iLogicVb.RuleName & ") to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
	Exit Sub
End If
Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim oSS As SelectSet = oPDoc.SelectSet
oSS.Clear
Dim oHSet As HighlightSet = oPDoc.CreateHighlightSet()
Dim oBody As SurfaceBody = oPDef.SurfaceBodies.Item(1)
Dim oFace As Face = oBody.Faces.Item(1)
oSS.Select(oFace)
oHSet.AddItem(oFace)

And here is an example of Option two:

(Keep in mind this won't work unless you have assigned that face a name in your model, and the name matches the name specified within the code.)

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kPartDocumentObject Then
	MsgBox("A Part Document must be active for this rule (" & iLogicVb.RuleName & ") to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
	Exit Sub
End If
Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
Dim oNE As NamedEntities = iLogicVb.Automation.GetNamedEntities(oPDoc)
Dim oSS As SelectSet = oPDoc.SelectSet
oSS.Clear
Dim oHSet As HighlightSet = oPDoc.CreateHighlightSet()
Dim oFace As Face = oNE.TryGetEntity("Top Face")
oSS.Select(oFace)
oHSet.AddItem(oFace)

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 6

Khoa_NguyenDang
Advocate
Advocate

Hi @WCrihfield 

Very thank for you help 

0 Likes

Hi @WCrihfield 

Very thank for you help 

Message 5 of 6

Khoa_NguyenDang
Advocate
Advocate

HI @WCrihfield 

 

I have tried your method 

As I see the HightSet is changing the color of my selected face and it doesn't come back to the normal when I stop select

I just when to highlight it in the sort time, and I wanna choose multi faces with Pick method

If you have other solution, please help me, thank you 

0 Likes

HI @WCrihfield 

 

I have tried your method 

As I see the HightSet is changing the color of my selected face and it doesn't come back to the normal when I stop select

I just when to highlight it in the sort time, and I wanna choose multi faces with Pick method

If you have other solution, please help me, thank you 

Message 6 of 6

WCrihfield
Mentor
Mentor
Accepted solution

Since I don't really know yet what you are wanting to do with the faces after they are selected, I'm showing three different processes here that all use the Pick function.

FYI:

- The document's SelectSet is where objects are normally temporarily stored when they are selected manually, or by the SelectSet.Select or SelectSet.SelectMultiple methods in code.

- As far as I know, the document's HighlightSet is purely for visual aid purposes, and is not necessary to use for normal selection purposes when selecting things by code.

- The ObjectCollection is a very handy object used to store all types of objects temporarily in a single variable, so they can either all be acted on at once later, or so they can be looped through later in some other process.

 

So, depending on your purpose for selecting the faces, you may not need all of these in the following code, but I have included them to show you how to create them and add to them.  Here's the new rule:

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kPartDocumentObject Then
	MsgBox("A Part Document must be active for this rule (" & iLogicVb.RuleName & ") to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
	Exit Sub
End If
Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
'if you have selected anything prior to starting this rule
'those things will be in this document's SelectSet
Dim oSelected As SelectSet = oPDoc.SelectSet
'clearing this set
oSelected.Clear
Dim oFaceCollection As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim oHSet As HighlightSet = oPDoc.CreateHighlightSet()
Dim oFace As Face
'the following word is a location marker for the GoTo method below
Repeat :
oFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select a part face.")
If oFace IsNot Nothing Then
	'add the Face to the 'actively selected' set of your document
	oSelected.Select(oFace)
	'add the Face to an ObjectCollection so you can work with them as a group later
	oFaceCollection.Add(oFace)
	'add the Face to the document's HighlightSet (visual aid only)
	oHSet.AddItem(oFace)
	'telling it to go back to where I inserted the word "Repeat", just before the Pick command
	'so it will continue to Pick more faces until Nothing is selected
	GoTo Repeat
Else
	'do nothing, just continue the rule
End If

'now all the Faces you selected are in those sets

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

Since I don't really know yet what you are wanting to do with the faces after they are selected, I'm showing three different processes here that all use the Pick function.

FYI:

- The document's SelectSet is where objects are normally temporarily stored when they are selected manually, or by the SelectSet.Select or SelectSet.SelectMultiple methods in code.

- As far as I know, the document's HighlightSet is purely for visual aid purposes, and is not necessary to use for normal selection purposes when selecting things by code.

- The ObjectCollection is a very handy object used to store all types of objects temporarily in a single variable, so they can either all be acted on at once later, or so they can be looped through later in some other process.

 

So, depending on your purpose for selecting the faces, you may not need all of these in the following code, but I have included them to show you how to create them and add to them.  Here's the new rule:

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kPartDocumentObject Then
	MsgBox("A Part Document must be active for this rule (" & iLogicVb.RuleName & ") to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
	Exit Sub
End If
Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
'if you have selected anything prior to starting this rule
'those things will be in this document's SelectSet
Dim oSelected As SelectSet = oPDoc.SelectSet
'clearing this set
oSelected.Clear
Dim oFaceCollection As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim oHSet As HighlightSet = oPDoc.CreateHighlightSet()
Dim oFace As Face
'the following word is a location marker for the GoTo method below
Repeat :
oFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select a part face.")
If oFace IsNot Nothing Then
	'add the Face to the 'actively selected' set of your document
	oSelected.Select(oFace)
	'add the Face to an ObjectCollection so you can work with them as a group later
	oFaceCollection.Add(oFace)
	'add the Face to the document's HighlightSet (visual aid only)
	oHSet.AddItem(oFace)
	'telling it to go back to where I inserted the word "Repeat", just before the Pick command
	'so it will continue to Pick more faces until Nothing is selected
	GoTo Repeat
Else
	'do nothing, just continue the rule
End If

'now all the Faces you selected are in those sets

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report