Author Topic: lisp for insert block from another drawing  (Read 4333 times)

0 Members and 1 Guest are viewing this topic.

tive29

  • Guest
lisp for insert block from another drawing
« on: June 09, 2017, 06:03:56 PM »
Code: [Select]
^C^C_insert;"Template";^C-insert;"*Block 1";0,0;;;
I use the above macro script to insert 'Block 1' from Template.dwg into current drawing at 0,0,0 & explode it. I have the folder location in my search path.

Please help to convert this macro script into a lisp that does exactly the same thing.

Thanks in advance
« Last Edit: June 09, 2017, 06:10:43 PM by tive29 »

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: lisp for insert block from another drawing
« Reply #1 on: June 10, 2017, 04:54:34 AM »
This lisp may be usefull for you
http://lee-mac.com/steal.html

tive29

  • Guest
Re: lisp for insert block from another drawing
« Reply #2 on: June 10, 2017, 07:11:46 AM »
This lisp may be usefull for you
http://lee-mac.com/steal.html

Use before in other situations. 
But What I need now is a single key command that
1) insert a predefined block from another drawing at 0,0,0
2) explode that block after the insertion



tedg

  • Swamp Rat
  • Posts: 811
Re: lisp for insert block from another drawing
« Reply #3 on: June 12, 2017, 11:28:53 AM »
This lisp may be usefull for you
http://lee-mac.com/steal.html

Use before in other situations. 
But What I need now is a single key command that
1) insert a predefined block from another drawing at 0,0,0
2) explode that block after the insertion


I'm sure there's a more elegant way,
But my hack on this would look like:
Code: [Select]

(defun c:foo ()
(command "-insert" "x:\\your folder\\template.dwg" "0.0,0.0,0.0" "" "" "") ;;inserts your master file from some defined file path
(Command "._erase" "l" "") ;;erases the block; last inserted
(command "-insert" "*block1"  "0.0,0.0,0.0" "" "" "") ;;inserts the block you want from the master file, *=explodes upon insertion
)
(princ)
..of course you could add a purge routine to this, zoom extents, whatever.
(you would need to edit the file name, block name and path to suit your needs)
Windows 10 Pro 64bit, AutoCAD 2023, REVIT 2023

tombu

  • Bull Frog
  • Posts: 289
  • ByLayer=>Not0
Re: lisp for insert block from another drawing
« Reply #4 on: June 13, 2017, 08:14:38 AM »
This lisp may be usefull for you
http://lee-mac.com/steal.html

Use before in other situations. 
But What I need now is a single key command that
1) insert a predefined block from another drawing at 0,0,0
2) explode that block after the insertion
Why not use a short lisp calling Steal to insert the block and explode it afterwards?  It requires the full path which you didn't provide.
Tom Beauford P.S.M.
Leon County FL Public Works - Windows 7 64 bit AutoCAD Civil 3D

tive29

  • Guest
Re: lisp for insert block from another drawing
« Reply #5 on: June 13, 2017, 08:46:31 PM »
It worked. But why is there this error at the end of the command?

Quote
Command: foo
-insert Enter block name or [?]: C:\Users\Documents\test\template_test.dwg
Units: Millimeters   Conversion:    1.0000
Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate]: 0.0,0.0,0.0
Enter X scale factor, specify opposite corner, or [Corner/XYZ] <1>: Enter Y scale factor <use X scale factor>:
Specify rotation angle <0>:
Command: ._erase
Select objects: l 1 found

Select objects:
Command: -insert Enter block name or [?] <template_test>: *block1 Specify insertion point for block: 0.0,0.0,0.0 Specify scale factor for XYZ axes:
Specify rotation angle <0>:
Command: FOO
Unknown command "FOO".  Press F1 for help.

This lisp may be usefull for you
http://lee-mac.com/steal.html

Use before in other situations. 
But What I need now is a single key command that
1) insert a predefined block from another drawing at 0,0,0
2) explode that block after the insertion


I'm sure there's a more elegant way,
But my hack on this would look like:
Code: [Select]

(defun c:foo ()
(command "-insert" "x:\\your folder\\template.dwg" "0.0,0.0,0.0" "" "" "") ;;inserts your master file from some defined file path
(Command "._erase" "l" "") ;;erases the block; last inserted
(command "-insert" "*block1"  "0.0,0.0,0.0" "" "" "") ;;inserts the block you want from the master file, *=explodes upon insertion
)
(princ)
..of course you could add a purge routine to this, zoom extents, whatever.
(you would need to edit the file name, block name and path to suit your needs)


tive29

  • Guest
Re: lisp for insert block from another drawing
« Reply #6 on: June 13, 2017, 08:49:12 PM »
I ever use LeeMac's steal to 'steal' but to have an insert & explode I am not sure how. How would you approach this for a lisp?

This lisp may be usefull for you
http://lee-mac.com/steal.html

Use before in other situations. 
But What I need now is a single key command that
1) insert a predefined block from another drawing at 0,0,0
2) explode that block after the insertion
Why not use a short lisp calling Steal to insert the block and explode it afterwards?  It requires the full path which you didn't provide.

tedg

  • Swamp Rat
  • Posts: 811
Re: lisp for insert block from another drawing
« Reply #7 on: June 14, 2017, 06:54:40 AM »
It worked. But why is there this error at the end of the command?
There were 1 too many sets of "" at the end of the insert routine, if you remove those, you should be all set.
Also for giggles add another (princ)
Code: [Select]

(defun c:fOO ()
(command "-insert" "x:\\your folder\\template.dwg" "0.0,0.0,0.0" "" "" "") ;;inserts your master file from some defined file path
(Command "._erase" "l" "") ;;erases the block; last inserted
(command "-insert" "*block1"  "0.0,0.0,0.0" "" "") ;;inserts the block you want from the master file, *=explodes upon insertion, removed one set of "" at the end
(princ) ;; added for silent return
)
(princ)


Hope it helps
Windows 10 Pro 64bit, AutoCAD 2023, REVIT 2023

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: lisp for insert block from another drawing
« Reply #8 on: June 14, 2017, 10:35:05 AM »
very small modification
- Create a new layer in case of the CLAYER is locked then purge
- Replace command with vl-cmdf

Code - Auto/Visual Lisp: [Select]
  1. (defun c:fOO ()
  2.   (setq clyr (getvar "clayer"))
  3.   (vl-cmdf "-layer" "N" "IB-Temp" "")
  4.   (setvar "clayer" "IB-Temp")
  5.   (vl-cmdf "-insert" "x:\\your folder\\template.dwg" "0.0,0.0,0.0" "" "" "") ;;inserts your master file from some defined file path
  6.   (vl-cmdf "._erase" "l" "") ;;erases the block; last inserted
  7.   (setvar "clayer" clyr)
  8.   (vl-cmdf "-purge" "LA" "IB-Temp" "n")
  9.   (vl-cmdf "-insert" "*block1"  "0.0,0.0,0.0" "" "") ;;inserts the block you want from the master file, *=explodes upon insertion, removed one set of "" at the end
  10.   (princ) ;; added for silent return
  11.   )

tive29

  • Guest
Re: lisp for insert block from another drawing
« Reply #9 on: June 16, 2017, 01:31:24 AM »
@Tedg - Thanks

@HasanCAD - Thanks for the modification. I like it. But how is "vl-cmdf" better?