How to drive custom properties with iLogic based on if a layer is turned on or off

How to drive custom properties with iLogic based on if a layer is turned on or off

ahiggins95G6B
Observer Observer
403 Views
2 Replies
Message 1 of 3

How to drive custom properties with iLogic based on if a layer is turned on or off

ahiggins95G6B
Observer
Observer

Is there any way to drive custom properties for a drawing based on the status of a layer.  Our title blocks utilize layers to show an "X" in the box.  There is a yes and a no check box.  The X for each check box is tied to a layer.  There is a yes layer and a no layer.  I would like to be able to create and set a custom property to show a certain value if the yes layer is turned on. 

0 Likes
404 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor

Here is something along those lines.  First it gets the drawing document, then searches for a layer named "yes".  If not found, it lets you know then exits the rule.  If found, it moves on to the next step.  It then looks for the custom iProperty.  I named it "Layer Yes Is On", because I didn't know what you called it or wanted to call it.  If it finds it, it updates its value (which is a Boolean in this case) with the value of whether or not that layer is turned on or not.  If the property is not found, it creates it with the value mentioned above.  If a boolean type value isn't what you had in mind, you can use the started line of code above to check the value of oYesLayer.Visible above that point, then create your own different type of value to give the custom iProperty.

 

oDDoc = ThisDrawing.Document
Dim oYesLayer As Layer
Try
	oYesLayer = oDDoc.StylesManager.Layers.Item("yes") 'is it capital or not?
Catch
	MsgBox("Couldn't find the Layer named 'yes'.  Exiting rule.", vbCritical, "iLogic")
	Exit Sub
End Try

'If oYesLayer.Visible Then 'Visible will be True when 'On'
'create or update the custom iProperty here
Dim oProp As Inventor.Property
Try
	oProp = oDDoc.PropertySets.Item(4).Item("Layer Yes Is On")
	oProp.Value = oYesLayer.Visible
Catch
	oProp = oDDoc.PropertySets.Item(4).Add(oYesLayer.Visible, "Layer Yes Is On")
End Try

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡 or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 3

ahiggins95G6B
Observer
Observer

I tried the code as entered below and created a layer called yes to test it.  If I use the top try statement then it works, but when I add in the 2nd try statement I get an error.  I created a custom property called "Layer Yes Is On" and the code works.  Is there something I need to change if the custom property does not exist?

 

Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))

System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
at Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

0 Likes