iLogic (or VBA) to revise display appearance of part(s)

iLogic (or VBA) to revise display appearance of part(s)

Anonymous
Not applicable
2,820 Views
11 Replies
Message 1 of 12

iLogic (or VBA) to revise display appearance of part(s)

Anonymous
Not applicable

I have an assembly with an assortment of part files.  Some part files need to be blue, while other part files need to be yellow.  \

 

The code below will run w/o any errors and the part files will have the correct display name, but the appearance of the part has not been updated.  I'm know there's something I'm missing, but all of the examples seems to deal w/the renderstyle, which is no longe exposed in the Inventor version I'm currently using (2015).

 

Anybody have any ideas as to how to proceed?

 

Thanks in advance!

 

M.

 

 

Sub Main()
Dim oCurrentDoc As Inventor.Document
Dim oDoc As Inventor.Document
Dim oPartDoc As PartDocument
'Dim oPartDef as PartDocument.ComponentDefinition
Dim oRefDoc As DocumentsEnumerator
Dim oTargetColor As RenderStyle
Dim oNewColor As RenderStyle
Dim i As Integer

Dim oPropSet As Inventor.PropertySet
Dim oPropSets As Inventor.PropertySets

Dim sPropSetName As String
sPropSetName = "Design Tracking Properties"
Dim sPropName
sPropName = "Description"

oCurrentDoc = ThisApplication.ActiveDocument

If oCurrentDoc.DocumentType = kAssemblyDocumentObject Then
    
    For Each oDoc In oCurrentDoc.AllReferencedDocuments
        If oDoc.DocumentType = kPartDocumentObject Then
            
            If InStr(oDoc.FullFileName, "BareCable") > 0 Then
            
                oPartDoc = oDoc
                oPropSet = oPartDoc.PropertySets.Item("Design Tracking Properties")
                
                If oPropSet.Item("Description").Value = "1192.5 KCMIL 61 AAC" Then
                    ' we make the item blue!
                    oPartDoc.ActiveAppearance.DisplayName = "Cadet Blue"
                    oPartDoc.Save
                End If
                
                If oPropSet.Item("Description").Value = "1192.5 KCMIL 38/19 ACSS/TW (STD STR)" Then
                    ' we make the item yellow!
                    oPartDoc.ActiveAppearance.DisplayName = "Yellow"
                    oPartDoc.Save
                End If
            
            End If
        End If
    
    Next
End If

ThisApplication.ActiveView.Update

End Sub
 
 
 
Accepted solutions (2)
2,821 Views
11 Replies
Replies (11)
Message 2 of 12

Anonymous
Not applicable
No help for the weary?

Hump day bump!
0 Likes
Message 3 of 12

RodrigoEiras
Advocate
Advocate

 

Hi,

 

After a quick look I have a doubt. Do you want to change the color of the part (in the part file), or just the color of the ocurrence of the part in the assembly?

 

What you are trying to do is the first thing, but it is more usual to do the second thing.

 

For the second one you may find this post helpful:

 

https://forums.autodesk.com/t5/inventor-general-discussion/ilogic-to-change-colors-of-parts/td-p/380...

 

Best regards

 

 

 

 

Message 4 of 12

Anonymous
Not applicable

We only have a single instance of each ipt in the assembly.  The ipt may be the same material as another ipt and thus will be colored based on the type of wire.  The part appearance field is revised, but the actual appearance of the part does not change.

 

2015-06-04-adesk-forum.JPG

 

If part is selected and the iProperties dialog box and opened, the appearance is still set as material and doesn't match what is shown in the quick access toolbar (QAT).

 

2015-06-04-adesk-forum-iprop.JPG

 

I shall review the code in the link you provided to see what I'm missing.

 

Thanks!

 

M.

 

0 Likes
Message 5 of 12

RodrigoEiras
Advocate
Advocate

 

It makes sense. What you should change is not the part apperance, but the ocurrence appearance. Now no matter what change you make on the part appearance, the ocurrence appearance will be still shown "As Material".

 

The ocurrences are used to allow you, for example, to have two ocurrences of the same part with different appearances in the same assembly.

 

I think the way shown in the post I sent you will lead you in the right direction.

 

Good luck!

 

 

 

 

 

0 Likes
Message 6 of 12

Anonymous
Not applicable

The second page of that forum thread crashes both Chrome and Internet Explorer.

 

2015-06-04-adesk-forum-crash.JPG

 

Not sure if the problem is on my end or the forum.

 

 

 

 

 

 

0 Likes
Message 7 of 12

RodrigoEiras
Advocate
Advocate

 

I have put this code together for you. You can place in the Select Case/End Select loop all component occurrence names and the colors you require.

 

The occurrence names are those shown in the browser in the assembly.

 

SyntaxEditor Code Snippet

    Dim oAssy As Inventor.AssemblyDocument
    Dim oCompOc As Inventor.ComponentOccurrence
      

    oDoc = ThisDoc.Document


    If oDoc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
      oAssy = oDoc
      For Each oCompOc In oAssy.ComponentDefinition.Occurrences
        Select Case oCompOc.Name
            Case "threaded fitting 1_2 3000:7"
                Component.Color(oCompOc.Name) = "Cyan"
            Case "threaded fitting 1_2 3000:4"
                Component.Color(oCompOc.Name) = "Red"
        End Select        

      Next
      
    End If

 

  

Capture.JPG 

 

I believe this is basically what you need.

 

 

Message 8 of 12

Anonymous
Not applicable
Accepted solution

Going thru VBA I am unable to access the iProperties from the component object.  

 

The color is determined from the Description iProperty, nothing to do the the name of the part. The ipt files are created on the fly by an IV add-in 

 

There is only one occurrance of each cable, each cable is unique for that one location.  There might be several hundred different ipts, each named differently, but the cable with a certain description iproperty will be blue, red, or yellow depending on their description.

 

My solution was to revise the IV add-in's (Substation Designer by Automation Force) integrated database to create the cable in my desired colors.  Not able to use iLogic to automate, had to do it by hand.  

 

I do appreciate the assistance and iLogic code, very helpful, just doesn't work in my situation.

 

Have a great weekend.

0 Likes
Message 9 of 12

MechMachineMan
Advisor
Advisor
Had you looked into modifying the appearance asset of the component occurrence? It's looking like this would probably accomplish what you need it to..

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 10 of 12

RodrigoEiras
Advocate
Advocate
Accepted solution

What about this?. It will require some adaptation but I think there is everything you require in it:

 

- Getting the part document from the assembly

- Accesing iProperties of the part

- Changing the part appearance based on the value of the iProperty

 

SyntaxEditor Code Snippet

    Dim oAssy As Inventor.AssemblyDocument
    Dim oCompOc As Inventor.ComponentOccurrence
    Dim oSubDoc As Inventor.Document
    Dim oCompDef As ComponentDefinition
    Dim oPart As Inventor.PartDocument
    
    Dim oAsset As Asset
    Dim oLib As AssetLibrary
    Dim sAppearance As String
    
    Dim invCustomPropertySet As PropertySet
    Dim invAppearanceProperty As Inventor.Property
    
    oLib = ThisApplication.AssetLibraries("Autodesk Appearance Library")
    oDoc = ThisDoc.Document

    If oDoc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
      oAssy = oDoc
      For Each oCompOc In oAssy.ComponentDefinition.Occurrences
        Select Case oCompOc.Name
            Case "TestCylinder:1"
                oCompDef = oCompOc.Definition
                oPart = oCompDef.Document
    
                invCustomPropertySet = oPart.PropertySets.Item("Inventor User Defined Properties")
                invAppearanceProperty = invCustomPropertySet.Item("Appearance")
                sAppearance = invAppearanceProperty.Value
                oAsset = oLib.AppearanceAssets(sAppearance)
                
                oPart.ActiveAppearance = oAsset
                        
        End Select        

      Next
      
    End If

 

Message 11 of 12

Anonymous
Not applicable

Worked like a charm.  Very cool.

 

Dim oAssy As Inventor.AssemblyDocument
Dim oCompOc As Inventor.ComponentOccurrence
Dim oCompDef as ComponentDefinition
Dim invCustomPropertySet As PropertySet

oLib = ThisApplication.AssetLibraries("Autodesk Appearance Library")
oDoc = ThisDoc.Document

If oDoc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
	oAssy = oDoc
	For Each oCompOc In oAssy.ComponentDefinition.Occurrences
		If InStr(oCompOc.Name, "BareCable") > 0 Then
           oCompDef = oCompOc.Definition
		   oPart = oCompDef.Document
		   InventorCustomPropertySet = oPart.PropertySets.Item("Design Tracking Properties")
		   sDescription = InventorCustomPropertySet.Item("Description").Value

			Select Case sDescription
				Case "1192.5 KCMIL 61 AAC"
					'MessageBox.Show("1195.5 KCMIL 61 AAC", "Cadet Blue")
					Component.Color(oCompOc.Name) = "Cadet Blue"

				Case "1192.5 KCMIL 38/19 ACSS/TW (STD STR)"
					'MessageBox.Show("1192.5 KCMIL 38/19 ACSS/TW (STD STR)", "Yellow")
					Component.Color(oCompOc.Name) = "Yellow"

				Case "636 KCMIL 37 AAC"
					Component.Color(oCompOc.Name) = "Red"
			End Select  
		End If
	Next
End If

Thanks again for the iLogic help!

 

Mike

0 Likes
Message 12 of 12

RodrigoEiras
Advocate
Advocate

Really happy to hear that! Smiley Happy

 

 

0 Likes