How to access the visible properties of a Mechanical object and modify their internal values?
Let a Surface Force Density object under a Harmonic Response analysis in Mechanical. Here is its Details window:
In order to access this object via Mechanical scripting, the following command could be issued:
sfd = ExtAPI.DataModel.GetObjectsByType(DataModelObjectCategory.ImportedSurfaceForceDensity)[0]
Its properties, shown in the screenshot above, can be accessed using this command:
sfd.VisibleProperties
In order to modify the Source Frequency property from Worksheet to All, this command could be used:
sfd.PropertyByName("PROPID_AnsoftTimeDefinition").InternalValue = 0 # 0: All, 1: Range, 2: Worksheet
Related, when I try:
print print "Contacts = ", oConnections.PropertyByName("Contacts").InternalValue
I get the error "Sequence contains no elements" But when I cycle through all the properties, the property and value are there:
oConnections = ExtAPI.DataModel.Project.Model.Connections oProperties = oConnections.VisibleProperties # for oProp in oProperties: print " " print "--------------------------------------" print " Property name: ", oProp.Name print "--------------------------------------" print " caption (actual display name): ", oProp.Caption print " internal value = ", oProp.InternalValue print " read only= ", oProp.ReadOnly print " visible = ", oProp.Visible print " APIName = ", oProp.APIName #
print "Contacts = ", oConnections.PropertyByName("Contacts").InternalValue
Yikes, how do we edit our posts? I have two "print print" that is wrong and the "This fails with..." jumps up in bold for some unknown reason (two hashtags in a row causes bold font?). I promise to learn "Markdown" or something similar in the future.