Author Topic: Help.QInsert block from path  (Read 1892 times)

0 Members and 1 Guest are viewing this topic.

PM

  • Guest
Help.QInsert block from path
« on: August 14, 2021, 06:44:59 AM »
Hi iam using two type of code to insert block .In the first method insert and explode the block and in the second code insert the block and stay as block

Code - Auto/Visual Lisp: [Select]
  1. (Defun c:block1 ()
  2. (setq scl 1000)
  3.  (setq scl1 (* scl 1))
  4.  (setq dt1 (getpoint "\n insert block:"))
  5.  (command "insert" "*block1" dt1 scl1 "0")
  6. (command "setvar" "clayer" "0")
  7. )
  8.  
  9.  
  10. (Defun c:block2 ()
  11. (COMMAND "_layer" "_m" "block2" "_c" "7" "" "")
  12.  (setq scl1 1)
  13.  (setq dt1 (getpoint "\n insert block:"))
  14.  (command "insert" "block2" dt1 scl1 scl1 "0")
  15. (command "setvar" "clayer" "0")
  16. )
  17.  
  18.  



I want to insert block from specific folder

Code - Auto/Visual Lisp: [Select]
  1. c:\\Myblock\\symbols
  2.  

I try to change the code to

Code - Auto/Visual Lisp: [Select]
  1. (Defun c:block1 ()
  2. (setq scl 1000)
  3.  (setq scl1 (* scl 1))
  4.  (setq dt1 (getpoint "\n insert block:"))
  5.  (command "insert" "c:\\Myblock\\symbols\\*block1" dt1 scl1 "0")  ;<----- not working
  6. (command "setvar" "clayer" "0")
  7. )
  8.  
  9.  
  10. (Defun c:block2 ()
  11. (COMMAND "_layer" "_m" "block2" "_c" "7" "" "")
  12.  (setq scl1 1)
  13.  (setq dt1 (getpoint "\n insert block:"))
  14.  (command "insert" "c:\\Myblock\\symbols\\block2" dt1 scl1 scl1 "0") ; <--- This works but i am not sure if it is the correct way to write it
  15. (command "setvar" "clayer" "0")
  16. )
  17.  
  18.  
  19.  


Thanks

BIGAL

  • Swamp Rat
  • Posts: 1411
  • 40 + years of using Autocad
Re: Help.QInsert block from path
« Reply #1 on: August 14, 2021, 11:06:13 PM »
The block has to have a physical name not a wildcard. Its looking for a block with * as 1st character.
A man who never made a mistake never made anything

mhupp

  • Bull Frog
  • Posts: 250
Re: Help.QInsert block from path
« Reply #2 on: August 14, 2021, 11:41:20 PM »
The explode block in the first example works because its at the front. its just reinserting block1 from definition the * means to explode it after insert.
in the second example reason its not working its looking for "*block1" in the symbols folder not "block1"

Code: [Select]
(Defun c:block1 ()
  (vl-cmdf "insert" "*c:\\Myblock\\symbols\\block1.dwg" pause "1000" "")  ;need the full path the * goes at the front of that path. pause is so you can pick the insert point.
  (setvar 'clayer "0") ;setvar with this command not in command line  ;try to avoid using command line less errors in the long run.
  (princ)                                                                                   
)
(Defun c:block2 ()
  (if (tblsearch "Layer" "block2")  ;checks for block2 & switches to it. if not makes it
    (setvar 'clayer "CHECK")
    (vl-cmdf "-Layer" "M" "block2" "C" "7" "" "")
  )
  (vl-cmdf "insert" "c:\\Myblock\\symbols\\block2" pasue "" "") ;defualts to 1 scale and 0 rotation
  (vl-cmdf "setvar" "clayer" "0")
)


PM

  • Guest
Re: Help.QInsert block from path
« Reply #3 on: August 15, 2021, 09:17:14 AM »
Thanks

mhupp

  • Bull Frog
  • Posts: 250
Re: Help.QInsert block from path
« Reply #4 on: August 15, 2021, 11:37:07 AM »
You have should do the same for the blocks. if its already in the drawing either redefine, reinsert, or alert you that its already in the drawing.

Code: [Select]
(if (tblsearch "block" "block2")  ;checks for block2
  (vl-cmdf "_.Insert" "block2=*c:\\Myblock\\symbols\\block2.dwg" pause "" "")  ;(vl-cmdf "_.Insert" "*block2" pause "" "") or (Alert "\nBlock2 is already defined in drawing")
  (vl-cmdf "_.Insert" "*c:\\Myblock\\symbols\\block2.dwg" pause "" "")
  (setvar 'clayer "0")
)
« Last Edit: August 15, 2021, 07:41:06 PM by mhupp »

PM

  • Guest
Re: Help.QInsert block from path
« Reply #5 on: August 17, 2021, 05:02:08 PM »
I want to ask a question. I use this code to insert an annotation attribiute block from path.

when i use this code the insert block is 4 time smaller !!!!!!!

Code - Auto/Visual Lisp: [Select]
  1. (Defun c:AnnotAROT1 ()
  2. (COMMAND "_layer" "_m" "_&#927;.&#932;" "_c" "61" "" "")
  3.  (setq scl1 1)
  4.  (setq dt1 (getpoint "\n insert block:"))
  5.  (setvar "attdia" 1)
  6.  (command "insert" "c:\\topocad\\MBLANNOT\\Symbols\\AnnotAROT1.dwg" dt1 scl1 scl1 "0")
  7.  (setvar "attdia" 0)
  8. (command "setvar" "clayer" "0")
  9. )
  10.  


When i delete the .dwg from the code the block insert in corrent scale

Code - Auto/Visual Lisp: [Select]
  1. (Defun c:AnnotAROT1 ()
  2. (COMMAND "_layer" "_m" "_&#927;.&#932;" "_c" "61" "" "")
  3.  (setq scl1 1)
  4.  (setq dt1 (getpoint "\n insert block:"))
  5.  (setvar "attdia" 1)
  6.  (command "insert" "c:\\topocad\\MBLANNOT\\Symbols\\AnnotAROT1" dt1 scl1 scl1 "0")
  7.  (setvar "attdia" 0)
  8. (command "setvar" "clayer" "0")
  9. )
  10.  


Can anyone  tell me why ???

Thanks

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Help.QInsert block from path
« Reply #6 on: August 17, 2021, 05:22:20 PM »
I'm surprised you get past this: (COMMAND "_layer" "_m" "_&#927;.&#932;" "_c" "61" "" "")

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

PM

  • Guest
Re: Help.QInsert block from path
« Reply #7 on: August 17, 2021, 05:34:37 PM »
This is my fault.I use greek and i don't translate it
Code - Auto/Visual Lisp: [Select]
  1. (COMMAND "_layer" "_m" "_O.T;" "_c" "61" "" "")
  2.  

PM

  • Guest
Re: Help.QInsert block from path
« Reply #8 on: August 18, 2021, 03:38:26 AM »
Any other ideas?
Thanks

mhupp

  • Bull Frog
  • Posts: 250
Re: Help.QInsert block from path
« Reply #9 on: August 18, 2021, 07:55:32 AM »
Are the drawing units the same between drawings? the path with the dwg it might pull all drawing information aswell.
without the dwg it might default all those settings to the drawing your inserting into and just pull in the geometry.

This is just a guess.
« Last Edit: August 18, 2021, 01:29:04 PM by mhupp »

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Help.QInsert block from path
« Reply #10 on: August 18, 2021, 11:09:16 AM »
Any other ideas?
Thanks
Try setting INSUNITS to 0.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

PM

  • Guest
Re: Help.QInsert block from path
« Reply #11 on: August 18, 2021, 11:51:48 AM »
I check the units from my template and the units in the dwg and i find that the Iighting was not International. I change it . Then i change the path in the lisp to c:\\topocad\\MBLANNOT\\Symbols\\AnnotAROT1.dwg. And works fine.

Thanks