Ilogic code to update styles and materials to autodesk appearance library

Ilogic code to update styles and materials to autodesk appearance library

ppolcynBNVFN
Enthusiast Enthusiast
939 Views
6 Replies
Message 1 of 7

Ilogic code to update styles and materials to autodesk appearance library

ppolcynBNVFN
Enthusiast
Enthusiast

I am trying to find some ilogic code to update the styles and materials of a part. I need the code to do a few simple steps:

 

  1. Switch compared materials to "Autodesk Appearance Library"ppolcynBNVFN_0-1689167340215.pngppolcynBNVFN_1-1689167388775.png

     

  2. Then select "Yes to All"
  3. Press "OK"
  4. Then press "Yes"ppolcynBNVFN_2-1689167461227.png

     

    Thanks in advance.
0 Likes
940 Views
6 Replies
Replies (6)
Message 2 of 7

WCrihfield
Mentor
Mentor

Hi @ppolcynBNVFN.  We do not have access to that built-in user interface dialog, or the controls within it through iLogic or Inventor's API.  However, a few years ago I created a VBA macro, then a similar iLogic rule that basically just executes the same command that clicking the main 'Update' button executes, which shows that main dialog.  Then it uses the System.Windows.Forms.SendKeys.SendWait() method in an attempt to simulate navigating that dialog using the keyboard keys.  This is not only risky, because the SendKeys methods are 'blind' (don't know where they are sending the keystrokes), but also unstable, because the steps may be different for different people, and different versions of Inventor.  You basically have to open that dialog normally (manually), then using only your keyboard keys, record exactly which keys you have to press, how many times you had to press them, and in what order you pressed them, in order to get the outcome you want.  Then attempt to simulate sending those same keyboard keystrokes to that dialog, after the command to open the dialog has been executed.  But you have to make sure that the keystrokes get sent to the right specific place, or they might cause problems somewhere else on your computer.  Also, my simple code did not include interacting with that drop-down menu, which can have more or less items listed within it on your computer than someone else has.  That would mean having to simulate a different number of keyboard key presses to get to the outcome you want than it would take for someone else.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 7

ppolcynBNVFN
Enthusiast
Enthusiast

This sounds great. Would you be able to share that code?

0 Likes
Message 4 of 7

WCrihfield
Mentor
Mentor

Attached are two text files.  One is for the VBA macro, and the other is for the iLogic rule.  Both do essentially the same thing.  However, since I first posted these online, I have heard that they did not always work as intended for everyone.  That likely means it may need to be customized a bit more for individual needs, through experimentation, but I am not sure.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 7

ppolcynBNVFN
Enthusiast
Enthusiast

This looks good. The only thing missing would be a line of code I can add to scroll in the list to select "autodesk appearance library" before updating.

0 Likes
Message 6 of 7

WCrihfield
Mentor
Mentor

There are other ways of updating things like styles, materials, appearances, and stuff like that through iLogic & Inventor's API, but the code generally needs to be customized for the different document types that could be active at the time.  For instance, drawings have tons more styles of all sorts than parts & assemblies do, and they need to be accessed and update differently, depending on the document type.  Then only parts really have multiple materials stored within, because assemblies don't contain any of their own original geometry, just the geometry from components you insert into them.  The only materials stored in an assembly, are when the assembly is the weldment type, and there two settings (default virtual component material, and default weld bead material).  Things like materials, appearances, and physical properties are stored in Attribute objects, which are very different objects than Styles.  Styles is an extremely generic term too, because of how many more specific types of styles there are.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 7

Frederick_Law
Mentor
Mentor
0 Likes