CAD.ObjMethod() allows calling a method (subroutine or function) on a graphical element inside a CAD based script safely.

Advanced topic Details ...

When the CAD object is used in script code the scripts operate in a specific background operational mode (a background thread for dealing with CAD operations)

This presents a problem if in the script code you try to manipulate a property of a Graphical object (such as a label or textbox). In >NET code this is referred to as an "Illegal Cross-Threaded Operation".

performing the following causes this to occur.

Dim b as QButton = C("button1")
b.backcolor=Color.Red ' illegal operation
CAD.Refresh ' this line causes the entire script to run in the background
b.backcolor=Color.gray ' illegal operation

To solve this problem in .NET you would normally Invoke a delegate on the primary thread of the application to execute the part of the code that deals with the GUI. As this is far to complex a simpler approach is applied to allow the same commands to be sent.

Dim b as QButton = C("button1")
CAD.ObjProperty(b, "backcolor") = Color.Red '  internally deals with cross threading.
CAD.Refresh ' this line causes the entire script to run in the background
CAD.ObjProperty(b, "backcolor") = Color.gray '  internally deals with cross threading.


obj (object) - the object you wish to call a method or property on.

PropName (string) - the name of the Property or method you want to call.

params (optional array) - zero, one or more parameters that are passed to the method or property to access it correctly, these must match the defined order of the parameters in the routine you are calling

  • if there are no parameters, leave it out.
  • if one parameter then pass it.
  • if more then one parameter pass them all in.

Return Value

If the Method being called is a function then the return value is returned (of whatever type it normally returns)

If the method is a Subroutine then Nothing is returned


Hide a Label

C("Label1").Hide        ' normal direct call of the method. ILLEGAL in CAD code.
CAD.ObjMethod(C("Label1"), "Hide")     ' protected / safe means to call the method.

Return a value from a function

dim s as string = C("Label1").ToString   ' call the method normally, is ILLEGAL in CAD code.
dim s as string = CAD.ObjMethod(C("Label1"), "ToString") ' safe way to return the string.