You are on page 1of 3

5/13/2015

Inventor2014API:SetPartmaterialManufacturingDevBlog

ManufacturingDevBlog
Home
Subscribe
Follow
UsefulLinks
Autodesk
AboutthisBlog
07/30/2013

Inventor2014API:SetPartmaterial
byVladimirAnanyev
WithInventor2014newAPIfunctionalityhasbeenintroducedthatfullysupportsconsistentmaterials.TheprimaryobjectinconsistentmaterialsisanAssetobject,whereAssetobjectsrepresentmaterials,physicalproperties,andcolors(whichare
nowreferredtoasappearances).Anassetisessentiallyacollectionofvalues.Youmayconsideramaterialasacombinationofitsphysicalproperties(density,yieldstrength,etc.)andhowitlooksoritsappearance.
Amaterialpropertyhassomebasicinformationthatidentifiesitname,description,type,etc.,anditreferencesaphysicalpropertiesassetandanappearanceasset.
Assetsexistwithinlibraries.InventorAPIHelpcontainsseveralcodesamplesthatwriteoutalloftheinformationassociatedwiththematerial,appearance,andphysicalpropertyassets.
ThefollowingVBAsamplesetdesiredmaterialfromtheAutodeskMaterialLibrarytotheactivepart.

PrivateSubSetMaterialToPart()
DimoDocAsPartDocument
SetoDoc=ThisApplication.ActiveDocument

DimNameAsString
Name="Copper"
'Name="Steel"

DimlocalAssetAsAsset
OnErrorResumeNext
SetlocalAsset=oDoc.Assets.Item(Name)
IfErrThen
OnErrorGoTo0
'Failedtogettheappearance
'inthedocument,soimportit.

'Getanassetlibrarybyname.
'Eitherthedisplayedname(which
'canchangedbasedonthecurrentlanguage)
'ortheinternalname
'(whichisalwaysthesame)canbeused.
DimassetLibAsAssetLibrary
SetassetLib=ThisApplication.AssetLibraries_
.Item("AutodeskMaterialLibrary")
'SetassetLib=ThisApplication.AssetLibraries_
'.Item("AD121259C03E4A1D92D859A22B4807AD")

'Getanassetinthelibrary
DimlibAssetAsAsset
SetlibAsset=assetLib.MaterialAssets.Item(Name)
'Copytheassetlocally.
SetlocalAsset=libAsset.CopyTo(oDoc)
EndIf
OnErrorGoTo0
http://adndevblog.typepad.com/manufacturing/2013/07/inventor2014apisetpartmaterial.html

1/3

5/13/2015

Inventor2014API:SetPartmaterialManufacturingDevBlog

'setmaterialtothepart
oDoc.ActiveMaterial=localAsset

'Selectthetopbrowsernodeofthemodelpane.
'ThisisaworkaroundtorefreshmaterialsinfointheUI.
CalloDoc.BrowserPanes.ActivePane.TopNode.DoSelect

EndSub
Youmightalsolike:

Settingthecolorof
apartin
conjunctionwithits
material

CreateChamfer
FeatureinPart
Document

AddNotefor
CenterlineofWork
FeatureinDrawing

CreateChamfer
Featurein
Assembly
Document
Linkwithin

Postedat01:00AMinInventor,VladimirAnanyev|Permalink
Comments

Maxencesaid...
IhadtouseoDoc.MaterialAssets.Item(Name)insteadofoDoc.Assets.Item(Name)tomakeitworks.
Reply03/17/2014at12:41PM

SerjeBulavskiysaid...
Hello,Vladimir.Exampleisincorrectori'mdoingsomethingwrong?
IfoundAssetandMaterialAssettypesindocumentationbutwheni'mtryingtouseit,VisualStudiofailingtofindthistypesinAPI.
VisualStudio2013,Inventor2014,C#5.0,.NET4.0
Reply01/07/2015at04:24AM

ACEDeSmedtsaid...
Thisdoesnotseemtoworkwellwithcustom/migratedlibrariesin2014.Theoldmethodstillworks(thankyoubackwardcompatibility)andusesmuchlesscodewitchresultsincleanercode:
DimMAsMaterial
SetM=ThisApplication.StylesManager.Materials(MaterialName)
Doc.ComponentDefinition.Material=M
Reply01/22/2015at06:35AM
http://adndevblog.typepad.com/manufacturing/2013/07/inventor2014apisetpartmaterial.html

2/3

5/13/2015

Commentbeloworsigninwith

Inventor2014API:SetPartmaterialManufacturingDevBlog

Typepad

Facebook

Twitter

Google+andmore...

(URLsautomaticallylinked.)

Emailaddressisnotdisplayedwithcomment.

Name
EmailAddress
WebSiteURL
Post Preview

http://adndevblog.typepad.com/manufacturing/2013/07/inventor2014apisetpartmaterial.html

3/3

You might also like