Custom Command Parameters in .NET

Custom Command Parameters in .NET

michael_robertson
Collaborator Collaborator
2,876 Views
2 Replies
Message 1 of 3

Custom Command Parameters in .NET

michael_robertson
Collaborator
Collaborator

Is there a way in the .NET api to create a custom command that takes parameters? Want to create the ability to call the netloaded command from an external application and send it parameters without user interaction.

Mike Robertson
FL. Dept. of Transportation
CADD Applications Developer
0 Likes
Accepted solutions (1)
2,877 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

Mike,

Yes. For my inter-process communication I use WCF, NetTcpBinding in particular, as this gives me the ability to have both server and client on different or the same machine(s). Because of threading issues within AutoCAD/Map3d I had to develop the Autodesk WCF side within a Windozes Form instantiated during IExtensionApplication.Initialize(). I have found WCF to be very reliable and full featured. Once I had finalized my approach to communication and realized how fast it was I developed a rather simple system for exchanging commands and data between the exe’s.

There are other approaches but I will let others speak to those. If you are interested and wish to explore the gory details we could take this offline.

r, dennis

0 Likes
Message 3 of 3

michael_robertson
Collaborator
Collaborator
Accepted solution

Thanks Dennis,

I actually just ended up creating a command using the <ListFunction> tag instead of the <CommandMethod> tag and it seems to do what I needed. I'm attaching the code incase anyone else runs into the same request.

 

Code:

If you need to create a custom autocad command that takes parameters the <CommandMethod> tag does not allow parameters.

 

BUT…

 

You can declare your custom command as a Lisp Function which can take parameters (but doesn’t have to) as follows:

 

        <LispFunction("MyFunction")> _

        Public Sub MyFunction(ByVal Args As ResultBuffer)

            ‘check if any parameters

            If Not Args = Nothing Then

                'step through the parameters

                For Each rb As TypedValue In Args

                    'check the param type

                    If (rb.TypeCode = Autodesk.AutoCAD.Runtime.LispDataType.Text) Then

                        'do something if text

                    End If

                    If (rb.TypeCode = Autodesk.AutoCAD.Runtime.LispDataType.ObjectId) Then

                        'do something if ObjectID

                    End If

                Next

            End If

        End Sub

 

To call the command from the command line enclose the command in parens as follows:

(MyFunction “myText”)

This calls the MyFunction command with a single text param = “myText”

Mike Robertson
FL. Dept. of Transportation
CADD Applications Developer