Material change using Inventor API

Material change using Inventor API

Anonymous
Not applicable
5,217 Views
9 Replies
Message 1 of 10

Material change using Inventor API

Anonymous
Not applicable

I changed the material using the vb.net code shown below.but after changing material the object is not updated ,the volume and mass didn't change ..why? any idea. here is my code

 

 

Dim oDoc As PartDocument
oDoc = inventorApp.ActiveDocument

Dim oDTProps As PropertySet
oDTProps = oDoc.PropertySets.Item("{32853F0F-3444-11d1-9E93-0060B03C1CA6}")
Dim oDesignerProp As Inventor.Property
oDesignerProp = oDTProps.ItemByPropId( _
PropertiesForDesignTrackingPropertiesEnum.kMaterialDesignTrackingProperties)
oDesignerProp = oDTProps.Item("Material")
oDesignerProp.Value = "Titanium"
oDoc.Update()

0 Likes
Accepted solutions (1)
5,218 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable

is it change the mass automatically when I change the material from api.?or any changes need to my code??

0 Likes
Message 3 of 10

jdkriek
Advisor
Advisor

You are only changing the iProp, that doesn't actually change the material

 

You need to use the ComponentDefinition like this:

 

oDoc.ComponentDefinition.Material.Name = "Titanium"
Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 4 of 10

jdkriek
Advisor
Advisor
Accepted solution

Actually, this may be the proper way to update everything, but still using ComponentDefinition

 

oDoc.ComponentDefinition.Material = oDoc.Materials.Item("Titanium")
Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 5 of 10

Anonymous
Not applicable

i tried this and it works but sometimes it takes awhile to update.

 

sometimes i have to go to the other open doc and back to see the updated material...

 

is there a code that can eliminate this delay update? or going back and forth to other open doc?

 

ive added doc.update but still no luck,.,,

 

 

 

inventor 2013

vault 2013

 

 

 

 

 

 

0 Likes
Message 6 of 10

jdkriek
Advisor
Advisor
iLogicVb.UpdateWhenDone = True
Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 7 of 10

Anonymous
Not applicable
im not using ilogic. im using vba.
0 Likes
Message 8 of 10

jdkriek
Advisor
Advisor

Indeed, sorry I forgot.

 

We are actually converting from VBA to External iLogic and VB.NET add-ins at work.

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


0 Likes
Message 9 of 10

Anonymous
Not applicable

Try this this will help me and working fine....just update the mass using this code  after changing the material.

 

 

Dim oPropSet As PropertySet
oPropSet = oPartDoc.PropertySets("Design Tracking Properties")
oPropSet.Item("Material").Value = DropDownList1.SelectedItem.Text
Dim materialDef As Material = oPartDoc.Materials(DropDownList1.SelectedItem.Text)
oPartDoc.ComponentDefinition.Material = materialDef
oPartDoc.Update()
Dim mass As Double = oPartDoc.ComponentDefinition.MassProperties.Mass
oPartDoc.SaveAs("F:\inventor\Proof Of Con\Cube\Cube_update1.ipt", True)
oPartDoc.SaveAs("F:\inventor\Proof Of Con\WebSite14\Documents\Cube_Update.ipt", True)

 

0 Likes
Message 10 of 10

Anonymous
Not applicable

what is the code for selecting something in the model explorer?

0 Likes