DCL List from Image Button

DCL List from Image Button

tcoley95E9Z
Enthusiast Enthusiast
4,700 Views
33 Replies
Message 1 of 34

DCL List from Image Button

tcoley95E9Z
Enthusiast
Enthusiast

Hello all,

 

I am working on a lsp that has a quick library for our day to day block design (we constantly result in many file paths to get to these so this would save a lot of time). The issue I am running across, however is when I select an image tile, I want to have a list populated of the blocks in that category. See image below for current DCL layout.

tcoley95E9Z_0-1707751303660.png

Temp has no function for now and I plan on keeping it that way

(Yes I know its messy right now.. just a draft)

 

This is my lisp code.

 

 

defun c:BTools (/ Dcl_Id% Folder$ Slides@ Slide1$ Slide2$ Slide3$ Slide4$ Return$ X# Y#)
  
  (princ "\nBTOOLS")(princ)
  
  ; Set Default Variables
  (setq Slides@ (list nil "Block Design" "Paper Space" "Plumbing" "WIP") ;; NAME OF THE .SLD FILE
        Slide1$ (nth 1 Slides@)
        Slide2$ (nth 2 Slides@)
        Slide3$ (nth 3 Slides@)
        Slide4$ (nth 4 Slides@)
        Folder$ "C:\\...\\...\\Documents\\"
        Return$ ""
  );setq
  
  ; Load Dialog
  (setq Dcl_Id% (load_dialog "MyDialogs.dcl"))
  (new_dialog "MySlideImages" Dcl_Id%)
  
  ; Set Dialog Initial Settings
  (set_tile "Title" " BTOOLS - TOOLS FOR DRAFTING")
  (set_tile "Text1" Slide1$)
  (set_tile "Text2" Slide2$)
  (set_tile "Text3" Slide3$)
  (set_tile "Text4" Slide4$)
  
  ; Adjust X# and Y# per image_buttom outline to fit slide_image
  (start_image "Slide1")(setq X# (- (dimx_tile "Slide1") 2))
  (setq Y# (- (dimy_tile "Slide1") 2))(end_image)
  (start_image "Slide1")(slide_image -5 -4 X# Y# (strcat Folder$ Slide1$))(end_image)
  (start_image "Slide2")(slide_image 1 1 X# Y# (strcat Folder$ Slide2$))(end_image)
  (start_image "Slide3")(slide_image 1 1 X# Y# (strcat Folder$ Slide3$))(end_image)
  (start_image "Slide4")(slide_image 1 1 X# Y# (strcat Folder$ Slide4$))(end_image)
  
  ; Dialog Actions
  (action_tile "Slide1" "(setq Return$ Slide1$)")
  (action_tile "Slide2" "(setq Return$ Slide2$)")
  (action_tile "Slide3" "(setq Return$ Slide3$)")
  (action_tile "Slide4" "(setq Return$ Slide4$)")
  (start_dialog)
  
  ; Unload Dialog
  (unload_dialog Dcl_Id%)
  (princ (strcat "\n" Return$))
  (princ)
  
)

 

 

 

0 Likes
4,701 Views
33 Replies
Replies (33)
Message 21 of 34

tcoley95E9Z
Enthusiast
Enthusiast
Yup I'll be working on that soon.. quick question. I've used insert block within a handful of codes but one thing I hate the most is either I need to define a getpoint to insert in which the preview of the block isnt shown (like normally grabbing a block and inserting from insert tool) or I need to do "-INSERT" where it forces me to scale and rotate despite doing this:
(command "-INSERT" blkfile "" "" "")
0 Likes
Message 22 of 34

paullimapa
Mentor
Mentor

one way I've done this is to use the viewctr variable as the insertion point and then move it afterwards:

(command"_.Move" (entlast) "" (getvar"viewctr"))

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 23 of 34

Sea-Haven
Mentor
Mentor

For me pop menus all the hard work has been done by Autocad, pop image menus support next etc so can go to more pages.

 

SeaHaven_0-1707885147403.pngSeaHaven_1-1707885183908.png

 

0 Likes
Message 24 of 34

scot-65
Advisor
Advisor

@tcoley95E9Z 

Helpful tips, tricks, suggestions, and improvements to your program.

 

Avoid executing select functions while the dialog box is open.

All vl-directory-list shall be declared/populated before opening the dialog.

Errors can occur if directory does not exist or does not contain target files.

Lag time can be decreased when selecting an image button and the list populating.

What happens if directory is changed? How to update the path to these directories?

List box is not populated when dialog is first opened.

What happens if "OK" is pressed before list box is populated?

 

I have a template that has four standard headers between new_dialog and start _dialog.

;** Initialize **

- initialize all image lists here or initialize before "new_dialog".

 

;** Set Tile **

- add a one-line description in the dialog informing user what to do now that dialog is opened "Tex1".

 

;** Mode Tile **

- if list box is blank when opening dialog, (mode_tile "accept" 1)

- if any image list failed, mode_tile = 1 the image button.

 

;** Action Tile **

- action_tile any image button and (mode_tile "accept" 0).

 

//DCL dialog constants
swh0 :spacer {width=0.0; height=0.0;}
swh1 :spacer {width=1.0; height=1.0;}
txac :text_part {alignment=centered;}
//now in the main dialog:
DLG :dialog {...
 swh0;
 :txac {key="Tex1";}
 swh1;

 

 

Path to the directories appear to be workstation (not DWG) specific information.

Either create registry entries or a CFG file to store these paths and a separate

dialog to assist defining these paths. One should not be updating programs

themselves due to environmental changes.

 

Hope this helps.

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

Message 25 of 34

CodeDing
Mentor
Mentor

@tcoley95E9Z wrote:
...one thing I hate the most is either I need to define a getpoint to insert in which the preview of the block isnt shown (like normally grabbing a block and inserting from insert tool) or I need to do "-INSERT" where it forces me to scale and rotate...

If you have Expresss Tools installed (most people do by default), then you can use:

(acet-ss-drag-move ...)

 

It's a great express tool! (confirmed it works in 2023, probably older versions also)

Worth noting that you would have to do some prep work to be sure it runs correctly (i.e. making sure the block is in the drawing, make sure the block is inserted already, and create error handler to delete block insertion if user cancels/exits during the drag-move operation)

 

acet-ss-drag-move.gif

 

Best,

Message 26 of 34

ВeekeeCZ
Consultant
Consultant

@tcoley95E9Z wrote:
... I need to do "-INSERT" where it forces me to scale and rotate despite doing this:
(command "-INSERT" blkfile "_s" 1 "_r" 0 pause)

 

possibly like is.

Message 27 of 34

Sea-Haven
Mentor
Mentor

So use getreal and getpoint so get user prompts.

 

(command "-INSERT" blkname "_s" (getreal "\nEnter scale ") "_r" (getreal "\nEnter Rotation ") (getpoint "\nPick insertion point "))

 

With attributes 

(command "-INSERT" "001" "_s" (getreal "\nEnter scale ") "_r" (getreal "\nEnter Rotation ") (getpoint "\nPick insertion point " (getstring "\nAtt1 " T)(getstring "\nAtt2 " T))
0 Likes
Message 28 of 34

tcoley95E9Z
Enthusiast
Enthusiast
1. I changed location of My Documents so not sure if that matches yours:

 

;        Folder$ "C:\\...\\...\\Documents\\"
        Folder$ (strcat(getenv"userprofile")"\\Documents\\")

 


Hey I was looking back on this thread and noticed this.. Will this return the file path up until the user? Something like this would be very useful for me as I am sharing these projects with my coworkers to streamline our workflow.

 

0 Likes
Message 29 of 34

paullimapa
Mentor
Mentor

the My Documents location is unique for each user logged in to Windows which is why in one of my Msg #20 reply I stated this:

"...now if you want this to work for everyone in the office you'll have to change the folder locations to a common area where those library of drawings reside..."


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 30 of 34

tcoley95E9Z
Enthusiast
Enthusiast
Okay that makes sense.. so there is no method to return a users current directory? What if you were to take the first part of a project directory?
0 Likes
Message 31 of 34

paullimapa
Mentor
Mentor

well the current directory may vary so if you want to point the folder to a set network location there's no reason to use the current directory. But usually the following code would return your current opened drawings folder location:

(getvar"dwgprefix")

You can always set it to a project folder location as well. But then again you'll have to make a change every time you switch to a different project. 

But if you're after a company wide library location then that folder location should be the same for everyone and that is the folder location to use in the lisp code.

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 32 of 34

tcoley95E9Z
Enthusiast
Enthusiast

Thanks Paul! Is there an enviornmental variable that would return an xref image file path? I know with relative paths, autocad removes the directory location up until after the users name. "..\..\..\Documents\" so I'm trying to, if possible, store a variable of everything after the users name with an xref image.

0 Likes
Message 33 of 34

paullimapa
Mentor
Mentor

You may want to review these threads to see the process of getting the xref image path:

https://www.theswamp.org/index.php?topic=35761.0

https://forums.augi.com/showthread.php?30329-Changing-Image-Path 

But as for relative paths on removing the directory up to the user name may not be always true.

Relative means relative to the current folder position. So if your folder position is many subfolders below the username then your relative path will start that many subfolders after.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 34 of 34

Sea-Haven
Mentor
Mentor

Just a couple of comments were I worked we had multiple users, so Like Paullimapa you should set up a directory for all your lisps, std dwgs etc so every user looks in the one spot. These should be set as support paths. The other problem similar to Xref was when a user saved say an image to their local drive rather than the server anybody else opening the dwg would get an error message about a missing image/xref. So make sure your Xref's are saved in same location as a dwg.