VBA Display part appearance color in MsgBox

VBA Display part appearance color in MsgBox

bionorica2015
Enthusiast Enthusiast
438 Views
6 Replies
Message 1 of 7

VBA Display part appearance color in MsgBox

bionorica2015
Enthusiast
Enthusiast

Hello

How can I get in vba name of current Appearance (library) and display in MsgBox?

An example color is Copper.

Thanks!

 

0 Likes
439 Views
6 Replies
Replies (6)
Message 2 of 7

MTheDesigner
Advocate
Advocate

If you are in the part workspace you can access it like this. If you are in the assembly workspace you will have to specify a component occurrence first.

Dim oDoc = ActiveDocument
MsgBox(oDoc
.ActiveAppearance.DisplayName)

Make sure you use  ActiveAppearance.DisplayName and not ActiveAppearance.Name because Name spits out its asset ID not its user readable name.

0 Likes
Message 3 of 7

WCrihfield
Mentor
Mentor

Hi @bionorica2015@MTheDesigner 's response will likely work in iLogic, but since you've got VBA right in your topic name, here is a VBA macro code for doing that same thing.

 

Sub DisplayAppearanceInMsg()
    If ThisApplication.ActiveDocumentType <> kPartDocumentObject Then
        Call MsgBox("This VBA macro only works if a Part document is active.", vbCritical, "")
        Exit Sub
    End If
    Dim oPDoc As PartDocument
    Set oPDoc = ThisApplication.ActiveDocument
    Call MsgBox(oPDoc.ActiveAppearance.DisplayName, vbInformation, "Active Appearance DisplayName")
    Call MsgBox(ThisApplication.ActiveAppearanceLibrary.DisplayName, vbInformation, "Active Appearance Library DisplayName")
End Sub

 

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

If you want and have time, I would appreciate your Vote(s) for My IDEAS :bulb: or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 7

bionorica2015
Enthusiast
Enthusiast

Thank you

Can You answer how You find needed method or property -needed code? Is there vba book or something or secret here?

0 Likes
Message 5 of 7

bionorica2015
Enthusiast
Enthusiast

Thank you

Can You answer how You find needed method or property -needed code? Is there vba book or something or secret there?

0 Likes
Message 6 of 7

MTheDesigner
Advocate
Advocate
I find this really helpful. https://help.autodesk.com/view/INVNTOR/2019/ENU/
This is for inventor 2019 which is what I am using but generally I just look through object trees one here or in the editor until I find what I need. Don't be afraid to make a test assembly or part and just mess around. It help a lot.
0 Likes
Message 7 of 7

WCrihfield
Mentor
Mentor

Hi @bionorica2015.  I don't think there is a one stop place to learn all you would need to know super easy or fast.  Since Microsoft developed that programming language for their Microsoft Office products, they are probably the best source (Link1, Link2, Link3) for learning the core functionality, but they are often super technical in their language explaining stuff, so it can be hard to follow at first.  But down within Inventor's online help page (like the link provided by @MTheDesigner), there is a folder full of 'sample programs' (Link4), and most of those examples are in VBA, so that is a fairly good place to peruse through.  I just picked up most of this type of stuff over time by looking at working examples, and doing my own trial and error testing while trying to customize existing stuff or create my own stuff.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes