Jump to content

create dropdown menu in autocad to select commands


Manuel_Kunde

Recommended Posts

Hi all, I am trying to write a lisp that will create a DropDown list in Autocad. With the selection from the fields I want to execute different commands that I have defined before.

 

(defun c:create_dropdown ()
  
(setq choise1 command1)
(setq choise2 command2)
(setq choise3 command3) 
(setq choise4 command4) 

(strcase (initget (getkword [choise1/choise2/choise3/choise4]))))
  
)

 

Link to comment
Share on other sites

Might just have to play around with the CUI and create your own tabs and ribbons. Creating a dropdown menu is a one-time setup each time you create a new one (unless your command has different names). This is an example of mine (a few of these are Lee's routines from his website):

 

image.thumb.png.61acc1be8e733f597923f4eeee5af031.png

 

Can be structure through the user interface using CUI command or whatnot and make your own partial customization files.

 

image.thumb.png.752ec80ab34e51bf782d5ee760dfbcce.png

 

 

Can create a new command and name it to whatever your command name is, and then put a macro like this (using "^C^C_" followed by the syntax of the command to be invoked. In the example below, the name of the command being invoked is P-PUT, hence ^C^C_P-PUT) :

image.thumb.png.0cd0ecf794fabb1eb5e023c8480f06fb.png

Link to comment
Share on other sites

If you want a drop down menu make a custom .mnu its just a text file using Notepad, going custom is much easier than using the CUI, a POP menu can have sub menu's as well. Making a custom mnu can be edited at any time and its a simple menuload to update, we had the mnu on the server so when a user opened Autocad they always got the latest version. You can make custom tool bars as well with custom icons again using notepad. More than happy to provide examples.

 

The other is if you want a pop DCL select use my Multi radio buttons.lsp that was written for this type of situation.

 

image.png.a8c166b4bf634324c8824790be1bb178.png      screenshot89.png.113799740b50660205f2c86465f1c5e7.pngMulti radio buttons.lsp

 

 

  • Like 2
Link to comment
Share on other sites

6 hours ago, BIGAL said:

If you want a drop down menu make a custom .mnu its just a text file using Notepad, going custom is much easier than using the CUI, a POP menu can have sub menu's as well. Making a custom mnu can be edited at any time and its a simple menuload to update, we had the mnu on the server so when a user opened Autocad they always got the latest version. You can make custom tool bars as well with custom icons again using notepad. More than happy to provide examples.

 

The other is if you want a pop DCL select use my Multi radio buttons.lsp that was written for this type of situation.

 

image.png.a8c166b4bf634324c8824790be1bb178.png      screenshot89.png.113799740b50660205f2c86465f1c5e7.png Multi radio buttons.lsp 3.38 kB · 15 downloads

 

 

 

Do you have an example, how a .mnu file should look like? I cant find anything here.

 

Link to comment
Share on other sites

8 hours ago, BIGAL said:

If you want a drop down menu make a custom .mnu its just a text file using Notepad, going custom is much easier than using the CUI, a POP menu can have sub menu's as well. Making a custom mnu can be edited at any time and its a simple menuload to update, we had the mnu on the server so when a user opened Autocad they always got the latest version. You can make custom tool bars as well with custom icons again using notepad. More than happy to provide examples.

 

The other is if you want a pop DCL select use my Multi radio buttons.lsp that was written for this type of situation.

 

image.png.a8c166b4bf634324c8824790be1bb178.png      screenshot89.png.113799740b50660205f2c86465f1c5e7.png Multi radio buttons.lsp 3.38 kB · 16 downloads

 

 

 

Okay, I'm now at the point where I can make a selection in AutoCAD.

I want to transfer a PDF that is stored locally in a folder to another folder. About the selection I want to set a variable.

 

Error message: stract Incorrect argument type stringp nil

 

(The stract path at the end still works, I defined it before).

 

image.png.ba291792c523ef3a59ed7a515f33769a.png

 

(defun c:pdftransfer (/ )

  (initget          "monday.pdf
                     tuesday.pdf"
  )
  
  (setq Request (getkword "Choose your pdf 
                         
                    [monday.pdf/
                     tuesday.pdf
                         
                    ] ")
  )
  
    (vl-file-copy (strcat "\\\\netlan.de\root\\de\\pdf\\" Request)
                  
                  (strcat Pathone Contact Pathtwo Order Paththree
                  Request)
    )
)

 

Link to comment
Share on other sites

2 hours ago, Manuel_Kunde said:

 

Okay, I'm now at the point where I can make a selection in AutoCAD.

I want to transfer a PDF that is stored locally in a folder to another folder. About the selection I want to set a variable.

 

Error message: stract Incorrect argument type stringp nil

 

(The stract path at the end still works, I defined it before).

 

image.png.ba291792c523ef3a59ed7a515f33769a.png

 


(defun c:pdftransfer (/ )

  (initget          "monday.pdf
                     tuesday.pdf"
  )
  
  (setq Request (getkword "Choose your pdf 
                         
                    [monday.pdf/
                     tuesday.pdf
                         
                    ] ")
  )
  
    (vl-file-copy (strcat "\\\\netlan.de\root\\de\\pdf\\" Request)
                  
                  (strcat Pathone Contact Pathtwo Order Paththree
                  Request)
    )
)

 

 

I'd presume it would have to do with the capitalisation of the initget prompts... maybe try "Monday.pdf Tuesday.pdf" instead.

The other thing would be the fact that when no bitcode is set for the initget, pressing Enter on getkword actually returns nil. So your other option would have to go the long way and do something like:

 

(setq Request 
        (cond 
            (   (getkword 
                    (strcat "\nChoose your pdf [Monday.pdf/Tuesday.pdf] <" 
                            (cond (Request) ("Monday.pdf"))
                            ">: "
                    )
                )
            )
            (Request)
            ("Monday.pdf")
        )
)

 

 

Link to comment
Share on other sites

22 hours ago, Manuel_Kunde said:

Hi all, I am trying to write a lisp that will create a DropDown list in Autocad. With the selection from the fields I want to execute different commands that I have defined before.

 


(defun c:create_dropdown ()
  
(setq choise1 command1)
(setq choise2 command2)
(setq choise3 command3) 
(setq choise4 command4) 

(strcase (initget (getkword [choise1/choise2/choise3/choise4]))))
  
)

 

The easiest way is to use DosLib

Once installed and loaded, use dos_popupmenu function.

(setq lst '("Moday.pdf" "Tuesday.pdf"))
(if
  (setq n (dos_popupmenu lst))
  (setq request (nth n lst))
)

 

Link to comment
Share on other sites

Stefan only problem is must have Doslib loaded. But same as Multi radio must load 1st. Not every one has doslib downloaded thats why I try to not use it. Adds to the complexity of getting user to download and install. Have enough problems getting end users to run provided code.


 

(load "DOSLib23x64.arx")


(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(if (not but)(setq but 1))
(setq request (strcat (ah:butts but "V"   '("Choose day " "Monday" "Tuesday" "Wednesday" )) ".pdf"))

 

But yes Doslib has some great functions 1 do use is progress bar.

Edited by BIGAL
  • Like 1
Link to comment
Share on other sites

3 hours ago, BIGAL said:

Stefan only problem is must have Doslib loaded. But same as Multi radio must load 1st. Not every one has doslib downloaded thats why I try to not use it. Adds to the complexity of getting user to download and install. Have enough problems getting end users to run provided code.


 


(load "DOSLib23x64.arx")


(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(if (not but)(setq but 1))
(setq request (strcat (ah:butts but "V"   '("Choose day " "Monday" "Tuesday" "Wednesday" )) ".pdf"))

 

But yes Doslib has some great functions 1 do use is progress bar.

 

Very good work, the Radio-lisp works perfectly! Thanks so far.

Is there a way that I can first confirm the selection with the ok Button, and then the window closes? Currently the window closes when I select something.

Link to comment
Share on other sites

On 8/5/2021 at 5:17 AM, Manuel_Kunde said:

 

Okay, I'm now at the point where I can make a selection in AutoCAD.

I want to transfer a PDF that is stored locally in a folder to another folder. About the selection I want to set a variable.

 

Error message: stract Incorrect argument type stringp nil

 

(The stract path at the end still works, I defined it before).

Keyword Specifications https://help.autodesk.com/view/ACD/2022/ENU/?guid=GUID-9ED8841B-5C1D-4B3F-9F3B-84A4408A6BBF

The string argument is interpreted according to the following rules:

Each keyword is separated from the following keyword by one or more spaces. For example, "Width Height Depth" defines three keywords.

Each keyword can contain only letters, numbers, and hyphens (-).

 

 

You're trying to use filenames with a period in them. Try using 

(initget "monday tuesday")
(setq Request (getkword "Choose your pdf [monday/tuesday] ")
       Request (strcat Request ".pdf")

 

  • Like 1
Link to comment
Share on other sites

When I wrote the code I wanted minimum picks hence closes on pick, but easy fix.

 

;(action_tile k  (strcat "(setq but "  (rtos x 2 0) ")" "(done_dialog)"))
(action_tile k  (strcat "(setq but "  (rtos x 2 0) ")"))
(if (= ahdef x)(set_tile k "1"))
(setq x (+ x 1))
)
;(action_tile "accept" (strcat "(setq but "  (rtos ahdef 2 0) ")" "(done_dialog)"))
(action_tile "accept"  "(done_dialog)")

 

Link to comment
Share on other sites

  • 2 weeks later...
On 8/6/2021 at 1:55 PM, tombu said:

Keyword Specifications https://help.autodesk.com/view/ACD/2022/ENU/?guid=GUID-9ED8841B-5C1D-4B3F-9F3B-84A4408A6BBF

The string argument is interpreted according to the following rules:

Each keyword is separated from the following keyword by one or more spaces. For example, "Width Height Depth" defines three keywords.

Each keyword can contain only letters, numbers, and hyphens (-).

 

 

You're trying to use filenames with a period in them. Try using 




(initget "monday tuesday")
(setq Request (getkword "Choose your pdf [monday/tuesday] ")
       Request (strcat Request ".pdf")

 

 

This works very simple. image.png.969d12101d2eea468ea7a61e709607b1.png

Edited by Manuel_Kunde
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...