Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Repeated entry of Block, with Vis State selection before placement

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
thomasPure
623 Views, 12 Replies

Repeated entry of Block, with Vis State selection before placement

I have a block in my model, I would like to perform the following routine:

1. user actions the routine with [VISLIST]
2. user is prompted to select an existing block within the drawing (There are 2 versions of the block which I would like this to work with, and I will spread it to more blocks in the furture)
3. Creates a dialog box (EG 1000x2000px)
4. creates a list within the dialog, generated from the visibility states of the block which has been selected, each entry in the list has a radiobutton
5. creates a scrollbar on the dialog when the list is too long (number of entries/vis states is approaching 100 per block)
6. user selects from the list of radiobuttons
7. when the selection is made, a new copy of the block is created, and the user chooses a placement point for the block. scale 1 rotation 0.
8. cycle back to step 3, open dialog box and select option again with a new instance of the same block, repeat steps until user escapes routine


I have been using ai to generate the code, (I know...) and i can get various sections of the routine working, but not all together (either get an empty pop-up, or none, or the vis state wont change, etc)

I will attach my testing dwg, with the blocks, and I will attach my current code attempts. but feel free to rip me apart and start over if thats better...

Thanks very much for any help given.

12 REPLIES 12
Message 2 of 13
paullimapa
in reply to: thomasPure

Isn't it just as easy as manually now:

1. selecting the block

2. make copy in place

3. clicking the visiblity states grip to show the list on the screen for selection

paullimapa_0-1728061339810.pngpaullimapa_1-1728061399771.png

4. then grab the grip of the block to move to new location?

paullimapa_2-1728061472203.png

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 3 of 13
Sea-Haven
in reply to: thomasPure

Have what you want, can pick a block and get visibility states. Big thanks to lee-mac. This version is for less than about 18 items need to change code to open a list box as looks like you have more than 18. Look at lines 35-37 to change to list box.

 

 

 

; Change dynamic block properties when inserting look at properties available.
; By Alan H June 2022

;; Get Dynamic Block Property Allowed Values  -  Lee Mac
;; Returns the allowed values for a specific Dynamic Block property.
;; Set Dynamic Block Visibility State  -  Lee Mac
;; Sets the Visibility Parameter of a Dynamic Block (if present) to a specific value (if allowed)
;; Get Visibility Parameter Name  -  Lee Mac
;; Returns the name of the Visibility Parameter of a Dynamic Block (if present)

(defun insdynv (blkname / pt obj lst ans)
(if (not LM:setdynpropvalue )(load "Lee-mac Dynamic block get-put"))
(setq pt (getpoint "\nPick a pt for block "))
(command "-insert" blkname "s" 1.0  pt 0)
(setq obj (vlax-ename->vla-object (entlast)))
(setq visval (LM:getvisibilityparametername obj))
(setq lst (LM:getdynpropallowedvalues obj visval))
(setq lst (cons "Please choose" lst))
(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(if (not AHbut)(setq AHbut 1))
(setq ans (ah:butts 1 "v"  lst))
(LM:SetVisibilityState obj ans)
(princ)
)

; set existing block visibilty

(defun insdyne (blkname / pt obj lst ans)
(if (not LM:setdynpropvalue )(load "Lee-mac Dynamic block get-put"))
(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(setq obj (vlax-ename->vla-object (car (entsel "\nPick a dynamic block "))))
(setq visval (LM:getvisibilityparametername obj))
(setq lst (LM:getdynpropallowedvalues obj visval))
(setq lst (cons "Please choose" lst))
(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(if (not AHbut)(setq AHbut 1))
(setq ans (ah:butts 1 "v"  lst))
(LM:SetVisibilityState obj ans)
(princ)
)

 

 

Message 4 of 13
thomasPure
in reply to: paullimapa

Hi, thanks for the reply.
This is currently the method used, and yes, thats the simplest way to do it.
However consider the process to do this takes 6 repetetive inputs from the user, for potentially many of the options listed per drawing sheet (copy, paste, vis, option, move, place), whereas the intended fix would be just two inputs (option, place). Therefore, time saved and RSI avoided, happy days!
Message 5 of 13
thomasPure
in reply to: Sea-Haven

Hi, thanks for the reply. 
This looks like the Lee Mac solution I have tried before, however this may have an extra section that I didnt notice before, so I will give it a go and hopefully its a fix. Thanks!

Message 6 of 13
paullimapa
in reply to: thomasPure

Actually both methods would take about 4 mouse clicks. But my proposal would be a simple copy block lisp function. So run copy block lisp and first click do block selection using code to retrieve the insertion point as base point. Second click is new block location which is required for either lisp code. Third click is on the visibility states grip of new block. Fourth click is visibility states selection. The fourth click with a custom dialog box would be the OK button to dismiss the dialog. 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 7 of 13
Sea-Haven
in reply to: thomasPure

Not sure about list box but in my Multi radio buttons.lsp I turned off the auto exit after pick a button, so not having the ok pick required.

Message 8 of 13
paullimapa
in reply to: thomasPure

Attached is the straight forward Copy Block lisp function cpb.lsp I mentioned in my last post which gives you the option to select any Block and will use the Insertion point as the Base point for the Copy. Then after selecting the Second point the new Block will be highlighted for you to pick on the Visibility States grip point to select a different Visibility States shown on the cursor menu. Then you can hit Enter to repeat the cpb.lsp function and since the last copied Block is still highlighted that will be the selected Block for the next Copy.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 9 of 13
thomasPure
in reply to: paullimapa

Thanks, I used some of this in my final product. I will post my solution as a seperate comment below. For now, its working enough, but I will continue making tweaks along the way to streamline it.
My next step is to make the vis state selection register one click as the selection, rather than needing to press ok in the dialog.
Message 10 of 13
thomasPure
in reply to: thomasPure

Heres the solution to my problem, thanks to all contributors.
I still have tweaks to make along the way, but hopefully this can help someone in the future.

Message 11 of 13
paullimapa
in reply to: thomasPure

to make it so that after you click the list it'll close the window without having to click OK, change this line of code from:

  (action_tile "lst" "(setq lsec  (atoi $value) )")

to:

  (action_tile "lst" "(setq lsec  (atoi $value) )(done_dialog)")

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 12 of 13
thomasPure
in reply to: paullimapa

Youve been a great help Paul, thanks!
I have two more wishes, to make this script work perfectly for me. Thanks for your help so far, please dont think me greedy.
I would love to be able to see the block 'in my hand' whilst the move/paste command is actioning. Currently, I have to estimate the size of the block based around the placement point.
Secondly, I intend to run this same script on blocks that have 1, or 2, placement grips. Is there a way for the script to examine the number of grips that the block has, and allow the user to input 1 or 2 placement points based on that?

Thanks so much
Message 13 of 13
paullimapa
in reply to: thomasPure

Not sure about the 2nd question. You'll have to provide a sample dynamic block with the 2 point placement.

Perhaps this link can provide a sample as solution:

https://www.cadtutor.net/forum/topic/66141-insert-dynamic-block-with-2-points/

As for the 1st question, replace these lines of code:

    ;; Prompt user for the new point to move the block
    (setq pt (getpoint "\nSpecify point to place the block: "))

    ;; Move the block from the default point to the user-specified point
    (vl-cmdf "_.move" blkent "" ipt pt)  ;; Move from (20,20) to new point (pt)

With these:

    (vl-cmdf "_.Move" blkent "" ipt)             ; see block preview for placement
    (while (= 1 (logand 1 (getvar 'CMDACTIVE))) (command pause)) ; while there's an active command pause

But the strange thing is that since you set the base point at (20,20), that is the source of the rubber band snap location. In order to see the block on the screen as you Move it into place, you'll have to exit the dialog, do a Zoom  Extents. Then run CallTag again to see the block during the Move command.

Any reason for not setting the base point using the selected block?

 


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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report