Jump to content

insert block from last inserted block


mbrandt5

Recommended Posts

I'm curious of a way to have multiple blocks inserted and have the block insert a specified distance from the previous inserted block of the command...

 

 

maybe using GetPoints just not sure how to do it...

 

 

Here is a multiple insert lisp I found on forums here...

 

 

(defun c:Insert (/ InsObj pt js ename nw_str)
  (initdia);brings up dialog box
  (command "._insert");starts command
  (while (> (getvar "cmdactive") 0)
     (command pause);;pauses for user input
 )
  (setq InsObj (entlast))
  (setq Inspt (cdr (assoc 2 (entget InsObj))))
  (while (setq pt(getpoint"\nSpecify insertion point: <press ENTER to stop>"))
  (command "_.-insert" Inspt pt "" "" ""))
  (princ)
)

Link to comment
Share on other sites

  • Replies 22
  • Created
  • Last Reply

Top Posters In This Topic

  • fabriciorby

    9

  • Commandobill

    8

  • mbrandt5

    6

try this very ugly code

(defun c:Insert2 (/ InsObj pt js ename nw_str lastpt distpt)
  (initdia);brings up dialog box
  (command "._insert");starts command
  (while (> (getvar "cmdactive") 0)
     (command pause);;pauses for user input
 )
  (setq InsObj (entlast))
  (setq Inspt (cdr (assoc 2 (entget InsObj))))
  (setq lastpt (cdr (assoc 10 (entget InsObj))))
  (while (not(setq distpt (getdist "\nType the distance: "))))
  (command "_.circle" lastpt distpt)
  (while (setq pt(getpoint"\nSpecify insertion point: <press ENTER to stop>"))
	(entdel (entlast))
	(command "_.-insert" Inspt pt "" "" "")
	(setq InsObj (entlast))
	(setq Inspt (cdr (assoc 2 (entget InsObj))))
	(setq lastpt (cdr (assoc 10 (entget InsObj))))
	(while (not(setq distpt (getdist "\nType the distance: "))))
	(command "_.circle" lastpt distpt)
)
(entdel (entlast))
   (princ)
)

Edited by fabriciorby
Link to comment
Share on other sites

Fabrício would you mind explaining to me what that code is doing exactly...

 

 

Though it didn't work I'd like to learn more lisp in actual code versus just reading about it

 

 

If not no big deal

Link to comment
Share on other sites

Fabrício would you mind explaining to me what that code is doing exactly...

 

 

Though it didn't work I'd like to learn more lisp in actual code versus just reading about it

 

 

If not no big deal

 

It didn't work? Have you typed "INSERT2" to start it? If so, could you please print your console here?

Yes, I can explain it to you, but print your console here first, let me take a look D:

Link to comment
Share on other sites

It didn't work? Have you typed "INSERT2" to start it? If so, could you please print your console here?

Yes, I can explain it to you, but print your console here first, let me take a look D:

 

Not sure what you were trying to do with that code, but it def did not work.

Link to comment
Share on other sites

Not sure what you were trying to do with that code, but it def did not work.

 

it works fine here, and fits the OP's objective

but yeah, the code is ugly because my purpose was to modify the already existing code

by the way, would you please print your console here too?

 

edit: give it a try now, i've edited the code a little bit

Link to comment
Share on other sites

it works fine here, and fits the OP's objective

but yeah, the code is ugly because my purpose was to modify the already existing code

by the way, would you please print your console here too?

 

edit: give it a try now, i've edited the code a little bit

 

Seems to be working now. There are definitely other ways of going about it, but you are right, it does fit his purpose.

Link to comment
Share on other sites

The direction doesn't have to be specified one direction would be fine...

 

 

 

Customization file loaded successfully. Customization Group: ACAD

Customization file loaded successfully. Customization Group: CUSTOM

Customization file loaded successfully. Customization Group: AUTODESKSEEK

Customization file loaded successfully. Customization Group: MODELDOC

Customization file loaded successfully. Customization Group: CONTENTEXPLORER

Customization file loaded successfully. Customization Group: APPMANAGER

Customization file loaded successfully. Customization Group: FEATUREDAPPS

Customization file loaded successfully. Customization Group: SKETCHUPIMPORTSKP

Customization file loaded successfully. Customization Group: DBCONNECT

Customization file loaded successfully. Customization Group: STEEL_SHAPES50

Customization file loaded successfully. Customization Group: EXPRESS

Loading AEC Base...

Loading AEC Base Extended...

Loading AEC Core...

Loading AEC Project Base...

Loading AEC Architectural Base...

Loading AEC Schedule...

Regenerating model.

Command:

Command:

Command:

Command:

Command:

Command:

Command:

Command:

Command:

Command:

Command:

Command:

Command:

Command:

Command:

Command:

Command:

Command:

Command:

Command:

Command:

Al's STEEL MILL Loaded. Type STL to use.Steel Shapes 5.0 © by CCAD inc. 2010, AISC 13.0; error: no function definition: OBJSELECTION

; error: no function definition: AUTOLOAD

Steel Shapes 5.0 © by CCAD inc. 2010, AISC 13.0

AutoCAD menu utilities loaded.

Al's STEEL MILL Loaded. Type STL to use.Steel Shapes 5.0 © by CCAD inc. 2010, AISC 13.0; error: no function definition: OBJSELECTION

Steel Shapes 5.1 by CCAD inc. © 2011.

alt.LSP for AutoCAD is loaded.

To view a slide of the fraction chart type alt.

dfactor-feet.LSP for AutoCAD is loaded.

To view a slide of the Drawing Factor chart type dfactor-feet.

dfactor-inches.LSP for AutoCAD is loaded.

To view a slide of the Drawing Factor chart type dfactor-feet. FILTER loaded.

Type HDLINE to start._UNDEFINE

Enter command name: EATTEDIT

Unknown command name.

VSF.LSP for AutoCAD is loaded.

To view a slide of the fraction chart type VSF.

AutoCAD menu utilities loaded.Steel Shapes 5.0 © by CCAD inc. 2010, AISC 13.0

Command: FileTab

Command: properties

Command: TOOLPALETTES

Command: COMMANDLINE

Command:

Command:

Command: Specify opposite corner or [Fence/WPolygon/CPolygon]:

Command: Specify opposite corner or [Fence/WPolygon/CPolygon]:

Command: Specify opposite corner or [Fence/WPolygon/CPolygon]:

Command: *Cancel*

Command: *Cancel*

Command: APPLOAD

DMZ.lsp successfully loaded.

Grid insert .lsp successfully loaded.

 

Command:

Command:

Command:

Command: APPLOAD

grid insert.lsp successfully loaded.

grid insert.lsp successfully loaded.

 

Command:

Command:

Command:

Command: INSERT2

._insert

Specify insertion point or [basepoint/Scale/X/Y/Z/Rotate]:

Command:

Type the distance: 10'

_.insert Enter block name or [?] <_archtick>: 15.40585711719873,15.02608410844836 Warning: If you are trying to insert the file: 15.40585711719873,15.02608410844836

it must be inserted using the = syntax.

Command: 120.000000

Command: ; error: Function cancelled

Command: *Cancel*

Command: Specify opposite corner or [Fence/WPolygon/CPolygon]:

Command: *Cancel*

Command: Specify opposite corner or [Fence/WPolygon/CPolygon]:

Command: *Cancel*

Command: *Cancel*

Command:

Command: *Cancel*

Command: *Cancel*

Command: INSERT

Specify insertion point or [basepoint/Scale/X/Y/Z/Rotate]:

Command: *Cancel*

Command: Specify opposite corner or [Fence/WPolygon/CPolygon]:

Command: _.erase 2 found

Command: INSERT2

._insert

Specify insertion point or [basepoint/Scale/X/Y/Z/Rotate]:

Command:

Type the distance: Specify second point: _.insert Enter block name or [?] <_archtick>: 14.16569767158643,14.80579059310322 Warning: If you are trying to insert the file: 14.16569767158643,14.80579059310322

it must be inserted using the = syntax.

Command: 10.836104

Command: INSERT2

Unknown command "INSERT2". Press F1 for help.

Command:

Specify insertion point: _.-insert Enter block name or [?] <_archtick>: _ArchTick

Units: Unitless Conversion: 0'-1.00000000"

Specify insertion point or [basepoint/Scale/X/Y/Z/Rotate]:

Enter X scale factor, specify opposite corner, or [Corner/XYZ] : Enter Y scale factor :

Specify rotation angle :

Command:

Type the distance: Specify second point: _.-insert Enter block name or [?] <_archtick>: 24.16998484980846,13.68220803577576 Warning: If you are trying to insert the file: 24.16998484980846,13.68220803577576

it must be inserted using the = syntax.

Command:

Command: INSERT2

Unknown command "INSERT2". Press F1 for help.

Command: INSERT2

Unknown command "INSERT2". Press F1 for help.

Command: INSERT2

Unknown command "INSERT2". Press F1 for help.

Command:

Specify insertion point: _.-insert Enter block name or [?] <_archtick>: _ArchTick

Units: Unitless Conversion: 0'-1.00000000"

Specify insertion point or [basepoint/Scale/X/Y/Z/Rotate]:

Enter X scale factor, specify opposite corner, or [Corner/XYZ] : Enter Y scale factor :

Specify rotation angle :

Command:

Type the distance: *Cancel*

; error: Function cancelled

Command: *Cancel*

Command: *Cancel*

Command:

Link to comment
Share on other sites

The direction doesn't have to be specified one direction would be fine...

 

Hey, I've edited the code, try again, it must work

Link to comment
Share on other sites

I think it's needed

 

Really? Let me walk you through your code to explain:

(defun c:Insert2 (/ InsObj pt js ename nw_str lastpt distpt)
  (initdia);brings up dialog box
  (command "._insert");starts command
  (while (> (getvar "cmdactive") 0)
     (command pause);;pauses for user input
 )
  (setq InsObj (entlast))[color="red"]looking for the last object created even though nothing has been inserted yet[/color]
  (setq Inspt (cdr (assoc 2 (entget InsObj))))[color="red"]Getting the name of a block that has yet to be inserted[/color]
  (setq lastpt (cdr (assoc 10 (entget InsObj))))[color="red"]Getting the location of the blokc, yet to be inserted[/color]
  (while (not(setq distpt (getdist "\nType the distance: "))))[color="red"]Getting a distance from a block that has yet to be inserted[/color]
  (command "_.circle" lastpt distpt)[color="red"]Random circle.....[/color]
  (while (setq pt(getpoint"\nSpecify insertion point: <press ENTER to stop>"))
	(entdel (entlast))
	(command "_.-insert" Inspt pt "" "" "")
	(setq InsObj (entlast))
	(setq Inspt (cdr (assoc 2 (entget InsObj))))
	(setq lastpt (cdr (assoc 10 (entget InsObj))))
	(while (not(setq distpt (getdist "\nType the distance: "))))
	(command "_.circle" lastpt distpt)
)
(entdel (entlast))
   (princ)
)

Link to comment
Share on other sites

Still not pretty, but give this a go.

(defun c:insert2 ( / dwg insPT block dir distpt )
 (if (and
(setq dwg (getfiled "Select Source Drawing" "" "dwg;dwt;dws" 16))
(setq insPT (getpoint "\nSpecify insertion point: ")))
   (progn
     (setq block (vla-insertblock
	    (vlax-get-property (vla-get-activedocument (vlax-get-acad-object)) (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace))
	    (vlax-3D-point (trans insPT 1 0))
	    dwg
	    1.0 1.0 1.0 0.0
	    ))
     (princ inspt)
     (while (and (setq distpt (getdist "\nType the distance: "))
	  (setq dir (getpoint "\nSpecify Direction: ")))
(setq block (vla-copy block))
(vla-move block
	  (vlax-3D-point
	    (trans insPT 1 0))
	  (vlax-3d-point
	    (setq insPT
		   (polar insPT
			  (angle insPT dir)
			  distpt))))
)
     
     
     )
   )
 )

Link to comment
Share on other sites

Really? Let me walk you through your code to explain:

(defun c:Insert2 (/ InsObj pt js ename nw_str lastpt distpt)
  (initdia);brings up dialog box
  (command "._insert");starts command
  (while (> (getvar "cmdactive") 0)
     (command pause);;pauses for user input
 )
  (setq InsObj (entlast))[color="red"]looking for the last object created even though nothing has been inserted yet[/color]
  (setq Inspt (cdr (assoc 2 (entget InsObj))))[color="red"]Getting the name of a block that has yet to be inserted[/color]
  (setq lastpt (cdr (assoc 10 (entget InsObj))))[color="red"]Getting the location of the blokc, yet to be inserted[/color]
  (while (not(setq distpt (getdist "\nType the distance: "))))[color="red"]Getting a distance from a block that has yet to be inserted[/color]
  (command "_.circle" lastpt distpt)[color="red"]Random circle.....[/color]
  (while (setq pt(getpoint"\nSpecify insertion point: <press ENTER to stop>"))
	(entdel (entlast))
	(command "_.-insert" Inspt pt "" "" "")
	(setq InsObj (entlast))
	(setq Inspt (cdr (assoc 2 (entget InsObj))))
	(setq lastpt (cdr (assoc 10 (entget InsObj))))
	(while (not(setq distpt (getdist "\nType the distance: "))))
	(command "_.circle" lastpt distpt)
)
(entdel (entlast))
   (princ)
)

 

I know this code is confusing (not my faulttttttt maybe next time I should consider writing a brand new one instead of trying to modify an existing one), but try reading it again:

(defun c:Insert2 (/ InsObj pt js ename nw_str lastpt distpt)
  [color="red"](initdia);brings up dialog box
  (command "._insert");starts command
  (while (> (getvar "cmdactive") 0)
     (command pause);;pauses for user input
 )[/color]

These lines are there for a reason, you've just ignored them.

So, yeah, the block is already inserted by the user, and that's why it's needed haha.

Link to comment
Share on other sites

These lines are there for a reason, you've just ignored them.

So, yeah, the block is already inserted by the user, and that's why it's needed haha.

I was mistaken. Sorry! Clearly it's been a long day.

Link to comment
Share on other sites

Thanks loads for the help...that worked great...

 

Anyway to make that snap to angles with osnaps?

 

Also I forgot to mention that the blocks have attributes to be prompted upon insert...The actual reason for this code is to insert grid lines and replace the grid numbers/letters of the grid lines upon insertion

 

Sorry I realize that makes things more complicated

Edited by mbrandt5
Link to comment
Share on other sites

Couldn't get the polar snap, but take a try

(defun c:blkInsert (/ blkName cmdEcho attDia blkPoint entCircle distPoint)
(if (tblsearch "block" (setq blkName (getstring "\nBlock name: ")))
	(progn
	(setq cmdEcho (getvar 'cmdEcho) attDia (getvar 'attDia))
	(setvar 'cmdEcho 0)
	(setvar 'attDia 1)
	(while (setq blkPoint (getpoint "\nSpecify insertion point: <press ENTER to stop>"))
		(if entCircle (entdel entCircle))
		(command "_.-insert" blkName blkPoint 1 1 0)
		(while (not (setq distPoint (getdist "\nType the distance: "))))
		(command "_.circle" blkPoint distPoint)
		(setq entCircle (entlast))
	)
	(if entCircle (entdel entCircle))
	(setvar 'cmdEcho cmdEcho)
	(setvar 'attDia attDia)
	)
	(princ (strcat "The block " blkName " doesn't exist in your drawing."))
)
(princ)
)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...