Set Appearance to ComponentOccurence

Set Appearance to ComponentOccurence

APvdM
Contributor Contributor
512 Views
3 Replies
Message 1 of 4

Set Appearance to ComponentOccurence

APvdM
Contributor
Contributor

Hello,

 

In an assembly I try to pick a color from an occurence an apply it to another one.
I got some code from the API help and i am adding some code.

 

 

Public Sub SetOccurrenceAppearance()
    Dim asmDoc As AssemblyDocument
    Set asmDoc = ThisApplication.ActiveDocument
    Dim assetLib As AssetLibrary
    Dim libAsset As Asset

    Dim localAsset As Asset
    On Error Resume Next
        
    Dim occ As ComponentOccurrence
    Set occ = ThisApplication.CommandManager.Pick(kAssemblyOccurrenceFilter, "Selecteer welke kleur overgenomen moet worden.")
    
    Set localAsset = occ.Appearance
    
    If Err Then
        On Error GoTo 0
        
        Set assetLib = ThisApplication.AssetLibraries.Item("Breston")
        
        Set libAsset = assetLib.AppearanceAssets.Item("Yellow")
        
        Set localAsset = libAsset.CopyTo(asmDoc)
    End If
    On Error GoTo 0
    
    Dim occ1 As ComponentOccurrence
    Set occ1 = ThisApplication.CommandManager.Pick(kAssemblyOccurrenceFilter, "Selecteer het te kleuren onderdeel.")
    
    Set occ1.Appearance = localAsset
    
End Sub

 

The last sentence (Set occ1.Appearance = localAsset) gives errors in the inventor VBA.

The same problem appears in Microsoft Visual Studio when i try: oOcc1.Appearance = occColor

 

Is there anyone who knows what the problem is?

 

0 Likes
513 Views
3 Replies
Replies (3)
Message 2 of 4

NachoShaw
Advisor
Advisor
Looks to me like you are collecting the appeal cell from an assembly part and attempting to apply it to the assembly itself instead of another part.

Wouldn't you need to select another part to copy the appearance to?

Nacho

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


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.


0 Likes
Message 3 of 4

NachoShaw
Advisor
Advisor
Oh hang on, I see the rest of the code now (reading on my phone)....

Have you tried

Set occ1.Appearance = occ.Appearance



Nacho

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


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.


0 Likes
Message 4 of 4

APvdM
Contributor
Contributor

Ah, that's a simple solution without the use of extra variabels.. Smiley Tongue

It works nice.. Thanks!

 

The code I sent yesterday works also, but only when I pick the color of an overrided part. I didn't try that earlier.

Thus picking the color of a parts that's not overrided gives an error.

Maybe because the Appearance (source) type or whatever gives problems?

 

For sake of completeness: Set occ1.Appearance = occ.Appearance is the right notation. Set before it is not right.

 

 

0 Likes