Author Topic: Insert block and ask for scale  (Read 3058 times)

0 Members and 1 Guest are viewing this topic.

like_citrus

  • Newt
  • Posts: 114
Insert block and ask for scale
« on: June 12, 2021, 12:06:49 AM »
I have a few blocks inserted from a pull down menu, and wanted to scale them as the block is inserted. The scale is variable and the user inputs this when the block is inserted.

The code below inserts blocks but needs something to ask for a scale.
All the blocks, except for one can be scaled using the "SCALE" command if done manually. The Dimension block can't be scaled using "SCALE", it's adjusted manually from the Properties toolbar by changing "Dim scale overall".

The process used:
- Create a folder and save the AutoCAD source files and menu (MNU) file in there.
- Load the menu file using the command "CUILOAD".
- Link this to AutoCAD by including in Support File Search Path. Tools/Options/Files tab. Add folder to Support File Search Path.
- Have the LISP code load automatically using the command "APPLOAD". Add the file to the Startup Suite.

MENU CODE
Code: [Select]
***MENUGROUP=MENU_TEMPORARY
***POP110
**CTOPopAID_DYNAMIC_TEMPORARY

            [Temporary]
            [<-Leader]^C^C(BlockInsertAndScale "CAD_Leader");
            [<-Dimension]^C^C(BlockInsertAndScale "CAD_Dimension");
            [--]

LISP
Code: [Select]
(defun BlockInsertAndScale (blkname)
    (command "_.-insert" (substr (strcat blkname "-" (menucmd "m=$(edtime,0,yymoddhhmmss)") "=" blkname) (+ (vl-string-position (ascii "_") blkname 1) 2)) pause 1 "" 0)
    (command "explode" "last")
)

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: Insert block and ask for scale
« Reply #1 on: June 12, 2021, 06:23:31 PM »
try replacing pause with (getreal "Enter scale")
A man who never made a mistake never made anything

like_citrus

  • Newt
  • Posts: 114
Re: Insert block and ask for scale
« Reply #2 on: June 12, 2021, 10:39:59 PM »
Thanks.
I did try it, something happened but it didn't work exactly.
There was this prompt in the command line: Specify insertion point or [Basepoint Scale X Y Z Rotate]
After typing in a value it just pasted the object. And it didn't paste in the location clicked on. Also I couldn't see a silhouette of the object before it was pasted like before.

Code: [Select]
(defun BlockInsertAndScale (blkname)
    (command "_.-insert" (substr (strcat blkname "-" (menucmd "m=$(edtime,0,yymoddhhmmss)") "=" blkname) (+ (vl-string-position (ascii "_") blkname 1) 2)) (getreal "Enter scale") 1 "" 0)
    (command "explode" "last")
     (setq blkname (getvar "dimscale")) 
)

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Insert block and ask for scale
« Reply #3 on: June 12, 2021, 11:49:50 PM »
AFAIK, first pause is for specifying insertion point and not for speciying scale... So IMHO, you should leave first pause and replace 1 with (progn (initget 3) (getreal "\nEnter scale : "))...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

like_citrus

  • Newt
  • Posts: 114
Re: Insert block and ask for scale
« Reply #4 on: June 13, 2021, 03:16:19 AM »
Thanks, that actually works.
I think it will work for all the blocks except as expected, for the Dimension block.
With the Dimension block, the arrow, offset, etc. are no scaled for some reason. If it's done manually, it's adjusted from the Properties toolbar by changing "Dim scale overall".

Code: [Select]
(defun BlockInsertAndScale (blkname)
    (command "_.-insert" (substr (strcat blkname "-" (menucmd "m=$(edtime,0,yymoddhhmmss)") "=" blkname) (+ (vl-string-position (ascii "_") blkname 1) 2)) pause (progn (initget 3) (getreal "\nEnter scale : ")) "" 0)
    (command "explode" "last")
)

like_citrus

  • Newt
  • Posts: 114
Re: Insert block and ask for scale
« Reply #5 on: June 14, 2021, 12:28:39 AM »
I'm struggling with the Dimension.
Rather than changing "Dim scale overall", would it be easier to change the following: "Arrow size", "Text height", "Text offset", "Dim scale linear".
Or alternatively, is there a setting in AutoCAD which when scaling dimensions, it changes the appearance. Or a setting in Dimension Styles?

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: Insert block and ask for scale
« Reply #6 on: June 14, 2021, 08:57:10 PM »
Like most styles you could get at the style prior to adding say a dimension, a simpler way may be to use entmake a dimension where you set the sizes, not tested but entmake often ignores current settings.
A man who never made a mistake never made anything

like_citrus

  • Newt
  • Posts: 114
Re: Insert block and ask for scale
« Reply #7 on: June 14, 2021, 09:54:15 PM »
OK thanks, how can that be done using LISP.

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: Insert block and ask for scale
« Reply #8 on: June 14, 2021, 10:18:08 PM »
If you use VL you can get at a lot of the dimension variables eg (vla-put-arrowheadsize 10)

So if you wanted the arrows to be twice the size (setq arrow (* 2.0 (vla-get-arrowheadsize obj)) (vla-put-arrowheadsize arrow)

Make the dim command etc then use (setq obj (vlax-ename->vla-object  (entlast)) to get the last object the Dimension.

Use Dumpit pick a dimension it will reveal the property names, then a get and put to change.

A man who never made a mistake never made anything

like_citrus

  • Newt
  • Posts: 114
Re: Insert block and ask for scale
« Reply #9 on: June 14, 2021, 10:33:50 PM »
Thanks I tried this to get started but still no good.
It actually stops other defuns in the same LISP file from running.

Code: [Select]
(defun TestForDim (blkname)
    (command "_.-insert" (substr (strcat blkname "-" (menucmd "m=$(edtime,0,yymoddhhmmss)") "=" blkname) (+ (vl-string-position (ascii "_") blkname 1) 2)) pause 1 "" 0)
(setq obj (vlax-ename->vla-object  (entlast))   
(setq arrow (* 2.0 (vla-get-arrowheadsize obj)) (vla-put-arrowheadsize arrow)
    (command "explode" "last")
)

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: Insert block and ask for scale
« Reply #10 on: June 14, 2021, 10:44:50 PM »
You said change a dim that was what I answered a block is totally different

Code: [Select]
(command "dim" "hor" (list 0 0) (list 10 0) (list 5 5)  ""  "exit")
(setq obj (vlax-ename->vla-object  (entlast)))
(setq arrow (* 2.0 (vla-get-arrowheadsize obj)))
(vla-put-arrowheadsize obj arrow)
A man who never made a mistake never made anything

like_citrus

  • Newt
  • Posts: 114
Re: Insert block and ask for scale
« Reply #11 on: June 14, 2021, 10:51:14 PM »
OK thanks but I'm really lost.
I tried incorporating your code but can't get it to work.
Is my understanding correct: That the block is first inserted and then your code changes it?

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: Insert block and ask for scale
« Reply #12 on: June 14, 2021, 11:33:58 PM »
A dimension is not a block, but a block can be made including a dimension, you need to post a dwg so can look at what you actually have.
A man who never made a mistake never made anything

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Insert block and ask for scale
« Reply #13 on: June 14, 2021, 11:38:45 PM »
A dimension is not a block, but a block can be made including a dimension, you need to post a dwg so can look at what you actually have.
Are you sure about that ? Name of dim: (2 . "*D###")
« Last Edit: June 14, 2021, 11:57:19 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

like_citrus

  • Newt
  • Posts: 114
Re: Insert block and ask for scale
« Reply #14 on: June 14, 2021, 11:50:07 PM »
I thought I had attached a dimension file in the original post.
Please see attached.

like_citrus

  • Newt
  • Posts: 114
Re: Insert block and ask for scale
« Reply #15 on: June 17, 2021, 04:33:38 AM »
This looks more difficult than I thought.
If the solution is possible, is there a link to a similar example I can follow.

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: Insert block and ask for scale
« Reply #16 on: June 17, 2021, 09:10:25 PM »
If the dim exists and you want to pick look at this, if you want to do dim and adjust straight away look at my other post using entlast.

Code: [Select]
(defun c:foo ()
(setq obj (vlax-ename->vla-object (car (entsel "\npick dimension "))))
(setq arrow (* 2.0 (vla-get-arrowheadsize obj)))
(vla-put-arrowheadsize obj arrow)
)
(c:foo)

Do repeatedly and arrows will grow.
A man who never made a mistake never made anything

like_citrus

  • Newt
  • Posts: 114
Re: Insert block and ask for scale
« Reply #17 on: June 18, 2021, 01:01:35 AM »
Sorry BIGAL I just can't understand what you mean.
The Dimension comes from a separate file which is inserted from the pull down menu.
The first command inserts it. The second command explodes it. The next part would be to scale it.
I don't know which applies in your question ... "If the dim exists" or "if you want to do dim and adjust straight away".

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: Insert block and ask for scale
« Reply #18 on: June 18, 2021, 07:39:34 PM »
Use the one above and just pick a dim, there are so many different variables in a DIM so I picked the arrows as an example. It doubles in size but you could enter a factor.
A man who never made a mistake never made anything

like_citrus

  • Newt
  • Posts: 114
Re: Insert block and ask for scale
« Reply #19 on: June 18, 2021, 10:00:49 PM »
OK thanks but that code is for picking a dimension. The dimension in question is inserted from a pull down menu. Also the scale factor is already input prior to inserting.
Thanks anyway for looking into.

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: Insert block and ask for scale
« Reply #20 on: June 19, 2021, 07:39:29 PM »
Add this where x is your dimscale.

Code: [Select]
(setvar 'dimscale X)
(command  "-dimstyle" "a" (entlast) "")
A man who never made a mistake never made anything

like_citrus

  • Newt
  • Posts: 114
Re: Insert block and ask for scale
« Reply #21 on: June 20, 2021, 01:24:35 AM »
This is what was required after exploding if it assists anyone.

Code: [Select]
(command "dimoverride" "dimscale" pause "" "p" "")