UpdateFromGlobal for Materials

UpdateFromGlobal for Materials

VGonsalves
Advocate Advocate
3,238 Views
26 Replies
Message 1 of 27

UpdateFromGlobal for Materials

VGonsalves
Advocate
Advocate

Hi

 

Is it possible to update a material "style" from the global styles using UpdateFromGlobal?

 

Currently I have a part whose density has been changed locally. I would like to revert this back to the defaults in the Design Data. I have read a few posts where you can update a partslist style using this command. For example http://forums.autodesk.com/t5/Inventor-Customization/ilogic-function-to-update-local-styles-to-match...

I tried replacing using the same idea and replacing the partslist with material but it doesn't work.

 

Can someone advise me on this.

 

Thank you

Accepted solutions (1)
3,239 Views
26 Replies
Replies (26)
Message 2 of 27

VGonsalves
Advocate
Advocate
Accepted solution
Hi All
I have resolved this problem. Following is the code if anyone needs it
Dim objDocument As Document
objDocument = ThisDoc.Document

objDocument.ComponentDefinition.Material.UpdateFromGlobal

It maybe simple and obvious to most but I struggled to work this out
Message 3 of 27

freesbee
Collaborator
Collaborator

...I've been searching & struggling 3 hours before finding this one!

Thank you so much!!

Massimo Frison
CAD R&D // PDM Admin · Hekuma GmbH
Message 4 of 27

WCrihfield
Mentor
Mentor

When I try using VGonsalves code it doesn't work.

I'm not seeing Material available under Component Definition.

Could you post a complete working rule that uses this method.

I've been searching this topic for hours too, but most posts are for Drawing Documents and styles.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 27

VGonsalves
Advocate
Advocate

I don't think this will help because the code is almost identical to the one posted earlier. Anyways here it is

 

Sub Main()
Dim objDocument As Document
objDocument = ThisDoc.Document

'Resets current material to match Style Library
objDocument.ComponentDefinition.Material.UpdateFromGlobal
End Sub

 

Maybe there is some other error in your code. If you like you can share your code and someone on this forum should be able to help if I can't

0 Likes
Message 6 of 27

WCrihfield
Mentor
Mentor

I am using Inventor 2020 Pro from PC on Windows 7 Enterprise SP1 64-it.

I am trying to create an external iLogic rule that will work for both Parts & Assembly files, that will do something similar to:  Manage Tab/Styles and Standards section Update/[Yes to All]/[OK].

I realize that tool is doing a fairly complex set of updates.

I've tried almost every code I've found throughout the forums, and trial & error coding so far, so I'm trying to break it down into individual types.  In this case, just the materials.

The problem I'm having with trying to use your code is, when I have defined a "Document" type Object,  there isn't a "ComponentDefinition" Object available for it when coding.

The only way I can get a "ComponentDefinition" is by first defining either a "PartDocument" type or "AssemblyDocument" type document.

Then after I do get a "ComponentDefininition" of a "PartDocument" or "AssemblyDocument", I don't have the "Material" object available in the list after the point (or period)..

See images below.

ComponentDefinition of Document.pngoCompDef list 1.pngoCompDef list 2.png

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 27

bradeneuropeArthur
Mentor
Mentor

dim objdocument as Partdocument 

or

dim objdocument as Assemblydocument 

 

Sorry you have been there already

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 8 of 27

freesbee
Collaborator
Collaborator

Hi!

Sorry: it's a very bad time for me. AU Vegas is behind the corner, I shall fly tomorrow morning and I still didn't pack my suitcase (and here it's 01:00!!).

Please keep in mind the following:

  1. it's absolutely impossible for me now to dig down into your specific issue (in 2 weeks I will gladly do it)
  2. I am absolutely ignorant in iLogic (I never needed, I never used it)
  3. I implemented the code from VGonsalves first in VBA and then in VBnet, which definitely works because it has updated more or less 220.000 ipt files with it
  4. I have only done it for IPTs because in my specific case it's 99% of the story (but could be equally done in IAMs)
  5. I have used this code in a batch processor that does a huge number of updating, cleaning, making nice on multiple inventor files... so the "AlignMaterials" is only a small part of the whole project (you can see an image of the batch processor here)

my inventor batch processormy inventor batch processor

 

So assuming that the code (VB.Net):

oPartDoc.ComponentDefinition.Material.UpdateFromGlobal()

works fine, I am giving you now the small additional detail that I had to figure out myself to make the batch processor work fine.

As you probably understood this program controls inventor and makes it do a number of actions. One of such actions is to read one specific custom iProperty (one string) seek the active material library for a material that is named exactly as the custom iProperty and then:

A) if a material asset with the same name is present in the file update it from material library

B) if no material asset with the same name is present in the file, seek the material library, copy it locally and assign it to the part

Case A) is under examination here, and I can grant that the code from VGonsalves works.

Since this program is designed to process thousands of files, inventor is restarted every random number of files (in the image 467) in order to clear cache and similar stuff. I have soon realized that, after restarting inventor, the seeking for assets in the material library was ranomly failing, even if everything was setup correctly.

I figured out that the first time one part is opened after a clean start, to some strange reason the material library CAN be not loaded. I could fix the problem decreasing the counter by 1 when this condition is met, and processing the file again: then everything got working perfectly, and I could go through 220.000 files within one weekend (with 10 workstations).

Maybe something similar is causing you the issue as well?

If I totally misunderstood your question, please bear till Nov 25: then I'll be back and I will be able to support you directly on VBA level.

 

Massimo Frison
CAD R&D // PDM Admin · Hekuma GmbH
0 Likes
Message 9 of 27

VGonsalves
Advocate
Advocate

I believe you are looking for this

 

Sub Main()
If ThisDoc.Document.DocumentType = kPartDocumentObject Then
Dim objDocument As PartDocument
objDocument = ThisDoc.Document
objDocument.ComponentDefinition.Material.UpdateFromGlobal
ElseIf ThisApplication.ActiveDocument.DocumentType = kAssemblyDocumentObject Then
Dim objDocument As AssemblyDocument
objDocument = ThisDoc.Document
MessageBox.Show("objDocument.ComponentDefinition.Material.UpdateFromGlobal won't work", "Assemblies do not have Material", MessageBoxButtons.OK, MessageBoxIcon.Warning, _
MessageBoxDefaultButton.Button1)
End If
End Sub

Message 10 of 27

WCrihfield
Mentor
Mentor

I tried that numerous times, but I still don't have the 'Material' option after the 'ComponentDefinition'.

I copied & ran your last two codes exactly, but neither is actually updating the material.

If these codes are working for you guys, but not for me, I have to wonder if there is some setting within my Inventor I don't have set the same as you do.

Within my 'Edit Rule' dialog box, on the Options Tab, Behavior of this ruls (section), I have the following options checked:

Supressed [unchecked], Silend operation [checked], Fire dependant rules immediately [checked], Don't run automatically [unchecked], Straight VB code [unchecked], Event triggers = All events enabled.

The iLogic Addin is set to automatically load (default) when the application loads.

I don't know what else to do to get this to work for me, the way it seems to be working for you guys.

I'm trying to run this as a normal external rule (like you write within the built-in Rule Editor), but is it possible that I may have to modify some settings within the VBA Editor, or activate more of its [Tools/References]?

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 11 of 27

WCrihfield
Mentor
Mentor

I also tried putting it into a new 'Module' of the ApplicationProject and running it as a macro, after making a few modifications for translating to the slightly different coding language.  But it didn't do anything.  No errors, just didn't do anything.

I have also been trying several other methods to do this too.

I've tried driving down through the 'For Each oAsset In oAssets...If...Then' loop method.

I've tried 'For Each oMaterialAsset In oMaterialAssets' loop method.

i've tried 'For Each oStyle In oStyles...If...Then' loop method.

Nothing is giving me the UpdateFromGlobal option within these objects.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 12 of 27

VGonsalves
Advocate
Advocate

Can you please clarify what doesn't work for you. I have tried it as an external rule and the code as shown works fine. The other settings you mentioned seem fine too

 

I use this code in a scenario as mentioned below

Through programming I alter the material colour and density for certain parts. If the part file is used for something else I alter the colour and density. So there are time when I need to revert back to the global style. This code helps me achieve it

 

Not sure why you are experiencing problems. Maybe try resetting the material manually to confirm that it can be achieved manually.

 

In terms of Material not showing up in the pop-up, do not worry it doesn't show up for me either but I can assure you it is working codeUntitled.png

0 Likes
Message 13 of 27

WCrihfield
Mentor
Mentor

 

I got that piece of code to work, after trying in on several different older part files. It is definately doing something, just not what I was hoping for.  This code only updates the single currently active material of the part file to match the active default material library's version of it.  I attached a couple of screen shots of the Update Styles dialog box before and after running this external rule on them.  I was hoping this would not just update the "Material", but also the currently active "Appearance".  Not every part uses the default appearance of the material. Sometimes the appearance is set to a different Appearance, that better represents our finished part.

But I suppose we've satisfied the title & purpose of this post at this point.

I will continue searching & experimenting on getting all the other things to update through iLogic code.

Along the way I figured out how to update all styles within a drawing file, and how to update all text styles in part files.

Thanks guys.

Update Styles screen shot - before.pngUpdate Styles screen shot - after.png

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 14 of 27

freesbee
Collaborator
Collaborator

If your component is having an appearance override clearly this is another asset to update. To my memory I did some experiments and it works exactly the same for appearances. Of course you need to adjust the code to grab the current appearance override, that could be applied in several different ways (per body, per part, per face...).

Also keep in mind that so called "in document styles" are discouraged by Autodesk, as for example one material/appearance asset saved in the file and not in the Material Library. If you have them you should really consider if it makes more sense to invest your energies in updating them, or to clean them up (which was the reason why I came close to this technique)

Massimo Frison
CAD R&D // PDM Admin · Hekuma GmbH
0 Likes
Message 15 of 27

WCrihfield
Mentor
Mentor

I'm not using 'in document styles' in that sense.  I do sometimes switch the appearance of a part from the default material assigned one a similar one from within the 'Autodesk Appearance Library' to switch the appearance of a metal part from flat to polished, or a the shade of stain on a wood part, etc. No custom created materials or appearances that only exist in the one part file.  And as I stated before, I'm not just trying to update the one AciveMaterial or ActiveAppearance.  I am basically trying to duplicate the effects of manually clicking on Update Styles, having both Styles & Materials checked, clicking on 'Yes to All', then clicking on 'OK'.

I can simulate parts of these actions using the CommandManager, ControlDefinitions,  etc. objects, but still work to do.

But this isn't what this specific post is about, so I wasn't going to continue talking about it on this specific post, since it's purpose has already been met.

Thanks anyway.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 16 of 27

reine_den_andra
Contributor
Contributor

Hi

Where can I found that batch file processor?

/Reine

0 Likes
Message 17 of 27

freesbee
Collaborator
Collaborator

...well, that BatchProcessor is something that normally I give to my customers for free, since I do not have the capacity to develop it into a commercial product with all documentation that would follow (as you see it says "alpha" in the title bar 😂 ). I give it to them, but they do not use it 🤣.

Normally they do not care of how I do it: they just want to see the result done, and once the result is achieved they are not interested in the program any more (logically: if you have already replaced border and titleblock on all your IDWs, you normally do not need to do that action again...). Clearly it also migrates files to the current version, which is another quite handy sub-product of it...

Massimo Frison
CAD R&D // PDM Admin · Hekuma GmbH
0 Likes
Message 18 of 27

ppolcynBNVFN
Enthusiast
Enthusiast

I think I am having this same problem you had 4 years ago. Did you ever find a solution by any chance?

0 Likes
Message 19 of 27

WCrihfield
Mentor
Mentor

Hi @ppolcynBNVFN.  Yes, several years ago.  I have learned a ton about iLogic, Inventor's API, and most of the common interactions with Inventor by code since then.  I also fully understand what was going on at that time now.  Back around 2016, Inventor changed from using the 'Material' & 'RenderStyle' objects, to using Asset objects to represent things like materials, appearances, and physical properties.  I believe around that same time, the 'Material' property of the PartComponentDefinition & AssemblyComponentDefinition became a 'hidden' property (no longer visible to the user, and no longer shown in help documentation), and was only continuing to be supported to help maintain the functionality of 'legacy' solutions that were using it.  Also, there is a generic ComponentDefinition object, that is not specific to any document type, then there are the more specific types, such as PartComponentDefinition & AssemblyComponentDefinition (and others), that are specific to a document type, and those more specific types are 'derived from' the generic type, and have more properties available to them than the generic type.  In that situation, the iLogic 'Intellisense' feature does not 'suggest' that some properties are available, due to the object being the generic version, but since the source document was really either a part or assembly, the properties are still supported even if they are not showing up in the Intellisense.

 

There are several ways to update Assets, but I have chosen to not use any 'hidden' properties in that process for several reasons, including because Autodesk warns us against doing so.  I have since developed several iLogic rules & VBA macros for this and similar tasks.  One of the solutions uses SendKeys.SendWait() to simulate interacting with the built-in user interface tool for updating materials & styles, and has worked very well for me for years now (VBA macro code & iLogic rule codes attached as text files).  But I do not recommend solutions involving the use of that SendKeys.SendWait method, due to the inherent dangers.  I have also attached another example iLogic rule (as a text file) for purging and updating model assets.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 20 of 27

CattabianiI
Collaborator
Collaborator

So the best solution and the one you're using and suggesting is the Purge and Update Model Assets script right?
Are there situations where the sendkey approach is better or the only way?

 

 

0 Likes