CAD Forum - tips, tricks, discussion and utilities for AutoCAD, Inventor, Revit and other Autodesk products [www.cadforum.cz]
Cesky English Deutsch
Login/Register:
 Visitors: 3178 
Plex.Earth connects AutoCAD and Google Earth

CAD tip CAD tip # 12024:

Question CAD 
 %  platform  category 
Q - question

How to create a custom iProperty or Parameter with iLogic?

A - answer How can I use an iLogic rule to automatically create custom parameters of a model or custom iProperties? How to handle situations when they already exist?

For both cases, you can use the coding construction Try Catch, ie. attempt to access the parameter or iProperty and catch any possible failure of this access.

The code for creating the iProperty "MyProperty" then looks as follows:

Dim propertyName As String = "MyProperty"
Dim propertyValue As String = "Test"

customPropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")
Try
      prop = customPropertySet.Item(propertyName)
Catch
      customPropertySet.Add("", propertyName)
End Try

iProperties.Value("Custom", propertyName) = propertyValue


The iLogic rule code for conditional creation of a custom/user parameter "MyParameter" can look e.g. as follows (assuming running the rule in an IPT part document):

Dim oParams As Parameters
Dim oPartDoc As PartDocument = ThisDoc.Document
Dim oPartCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
oParams = oPartCompDef.Parameters

Dim oUserParams As UserParameters = oParams.UserParameters

Try
  p = Parameter("MyParameter")
Catch
  oUserParams.AddByValue("MyParameter","MyValue", UnitsTypeEnum.kTextUnits)
End Try
Inventor
100% *  CAD 
7.10.2018    231×  
applies to: Inventor ·

See also:
Tip 11983:How to use iLogic code to fill username into iProperties?
Tip 11801:What is the difference between ThisDoc.Document and ThisApplication.ActiveDocument in iLogic?
Tip 11542:How to reset the top browser node name back to the file name?


Back   All CAD Tips All CAD tips&tricks

How to print 3D characters designed in Autodesk Character Generator? « | » What does the padlock icon mean on the DWG tab in AutoCAD?

Have we helped you? If you want to support the CAD Forum web service, consider buying one of our CAD applications, or our custom software development offerings, or donating via PayPal (see above). You may also add a link to your web - like this "fan" link: CAD Forum - tips, utilities, blocks for Autodesk products
CAD:    OS:    Categ: 
Text:  FAQ glossary   



Featuring:
DwgTextTranslator translates a series of drawings from one language to another using MS Access.
Download a fully functional trial version.


Please use these tips at your own risk.
CAD Studio (Xanadu) is not responsible for possible problems that may occur as a result of using any of these tips.
TOPlist