Creating CommandMethod from existing function

Creating CommandMethod from existing function

Anonymous
Not applicable
771 Views
2 Replies
Message 1 of 3

Creating CommandMethod from existing function

Anonymous
Not applicable

Hey all,

I'm working on some VB.NET commands. I find that I have a series of commands that are really repetitive codewise, with only three pieces of information different. I'd like to store those pieces of information in an array to make them quickly changeable and just iterate through them, creating a command for each one that calls the same function, just passing in those pieces of information.

    'Inserts a Source Four 19 degree on the next mouse click
    <CommandMethod("ins19")> Public Sub cmdIns19()
        InsertBlock("19blockname", "19blocklocation")
    End Sub

    'Inserts a Source Four 26 degree on the next mouse click
    <CommandMethod("ins26")> Public Sub cmdIns26()
        InsertBlock("26blockname", "26blocklocation")
    End Sub

The code above is an example, it's going to just repeat for every single block.

Is there a way to create that differently so I'm not repeating that code and I can just pull the information from a data structure that's a little more manageable?

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

zrobert
Advocate
Advocate

Hi;

Can you explain a little more in detail? If I understand correctly, your commands are for block insertion, with blockname, blocklocation, and rotation. These parameters are defined in advance, and you have defined a separate command for each combination of parameters. You already have a defined function InsertBlock (blockname, blocklocation), which receives the block name and position as arguments. Add her third argument rotation. Make only one command, and use PromptIntegerResult to allow the user to choose the desired block type.

This is just a quick example. I have not used VB for a long time, so there is probably some error in the code, but that's one of ideas.

 

 

<CommandMethod("insTest")> Public Sub cmdIns19()
Dim pIntOpts As PromptIntegerOptions = New PromptIntegerOptions("")
pIntOpts.Message = vbCrLf & "Enter the type of block: "
Dim pIntRes As PromptIntegerResult = acDoc.Editor.GetInteger(pIntOpts)
 
If pIntRes.Status = PromptStatus.Ok Then
    DoJob(pIntRes.Value);
End If
 
End Sub
 
Public Sub DoJob(Integer option)
Select Case number
    Case 19
        InsertBlock("19blockname", "19blocklocation", 19)
    Case 26
        InsertBlock("19blockname", "19blocklocation", 26)
    ...
 ...
 ...
End Select
End Sub
0 Likes
Message 3 of 3

Virupaksha_aithal
Autodesk Support
Autodesk Support

Hi,

 

Try using keywords in string input, which will allow you to use single command with same code.

Please look at https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/AutoCAD-NET/files/GUI... .

Shows all the rotations you have as keywords for user to chose

 

 



Virupaksha Aithal KM
Developer Technical Services
Autodesk Developer Network

0 Likes