Exploding Blocks on Insert

Exploding Blocks on Insert

dbrblg
Collaborator Collaborator
4,086 Views
6 Replies
Message 1 of 7

Exploding Blocks on Insert

dbrblg
Collaborator
Collaborator

Lisp again Smiley Surprised

 

I have a lisp function which I use to insert blocks:

(defun c:TestFunction ()
	(setq FF1 (Find "drawing.dwg"))
        ;returns "c:\drawing.dwg"
	(if FF1
	  (PROGN
		(setvar"ATTREQ" 0)
		(command "_.INSERT" (strcat "*" FF1) pause 1.0 1.0 0.0)
		(setvar"ATTREQ" 1)
	  )
	)
	(princ)
)

What I want is to explode on insert.  For this, I believe you need an '*' before the file name.  The prblem I'm having is where to put this '*' as all I get is various errors (depending on where I place it) ranging from nil and too many arguments to just doing nothing.

 

So far, I have tried (without success) Smiley Mad

(setq FF1 (Find *"drawing.dwg"))
and
(setq FF1 (Find "*drawing.dwg"))

also

(command "_.INSERT" (strcat "*" FF1) pause 1.0 1.0 0.0)
and
(command "_.INSERT"  *FF1 pause 1.0 1.0 0.0)

can anyone tell me the correct way to do correct this please?

 

Thanks

0 Likes
4,087 Views
6 Replies
Replies (6)
Message 2 of 7

dbroad
Mentor
Mentor

The correct function is findfile.

 

(setq dwg (findfile "yourfile.dwg"))

 

You don't need to adjust the attreq variables because there won't be any attribute requests when the drawing is inserted and exploded at the same time.

 

Your actual insert command seems fine.  The asterisk is where it should be in the strcat function.

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 3 of 7

dbrblg
Collaborator
Collaborator

Actually the 'find' function is a homebrew..... because I deal with AutoCAD Electrical, I needed a way to not only search the AutoCAD paths (which you'd normally do with findfile) but also the AutoCAD Electrical project paths hence the custom 'all-in-one' function!!

 

There is a typo however, albeit probabily insignificant (as it is only a comment) which is the returned path is actually

;returns "c://drawing.dwg"

 

But this aside. 

 

Originally this was a AutoCAD menu customisation and contained

 

^C^C^P(setvar"ATTREQ" 0) (command "_.INSERT" "*drawing" pause 1.0 0.0)(setvar "ATTREQ" 1)

Note, the '*' asterisk which DID explode on insertion.  All I tried to do was to convert this in to a .lsp file which is on the server for all to use when importing an AutoCAD Electrical project.

 

 

 

 

Message 4 of 7

ВeekeeCZ
Consultant
Consultant

@dbrblg wrote:

Actually the 'find' function is a homebrew..... because I deal with AutoCAD Electrical, I needed a way to not only search the AutoCAD paths (which you'd normally do with findfile) but also the AutoCAD Electrical project paths hence the custom 'all-in-one' function!!

 

There is a typo however, albeit probabily insignificant (as it is only a comment) which is the returned path is actually

;returns "c://drawing.dwg"

 

But this aside. 

 

Originally this was a AutoCAD menu customisation and contained

 

^C^C^P(setvar"ATTREQ" 0) (command "_.INSERT" "*drawing" pause 1.0 0.0)(setvar "ATTREQ" 1)

Note, the '*' asterisk which DID explode on insertion.  All I tried to do was to convert this in to a .lsp file which is on the server for all to use when importing an AutoCAD Electrical project.

 


 

I'm little bit lost in your post, but this works:

 

(command "_.INSERT" "*c:/Users/User/Desktop/_download/drawing1.dwg" pause 1.0 "" 0)

 

and this as well:

(command "_.INSERT" (strcat "*" (findfile "drawing1.dwg")) pause 1.0 0.0)

 

 

Note that there is one / (or two \\) in the path. Two of // is not correct.

0 Likes
Message 5 of 7

dbroad
Mentor
Mentor

I agree with  @ВeekeeCZ

 

Your command:

(command "_.INSERT" (strcat "*" FF1) pause 1.0 1.0 0.0)

should be fine assuming Find is doing its work. Nesting that command statement in the if statement is good but if Find is not returning a correct string, then just checking if FF1 is not nil (which is what you are doing) may not be enough.  Your error is most likely in your homebrew Find command.

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 6 of 7

dbrblg
Collaborator
Collaborator

Now, it does something different Smiley Surprised

 

When I have

(command "_.INSERT" FF1 pause 1.0 1.0 0.0)

and I run the function, I am prompted where to put the block and as I move the mouse around the block is visible at the cursor.  The only thing is that when I click, the block is placed where I select but is not exploded - as you would expect.

 

When I change this to

(command "_.INSERT" (strcat "*" FF1) pause 1.0 1.0 0.0)

There are two noticable differences. The first is that when I move the mouse to the point I want to place the block, it is not visible at the cursor so I cannot see the block outline.  The second thing is that when I click where to place the block, it is inserted and it does explode but for some reason it is at an angle Smiley Surprised

The only difference is strcat and an asterisk, no where do I tell it not to give me a preview at the cursor (don't know how to do this) and no where do I tell it to rotate the block at an angle.

 

What on earth is going on?

 

 

 

0 Likes
Message 7 of 7

dbroad
Mentor
Mentor

That's the nature of the beast.  By insert and exploding at the same time, the block definition is never brought into the drawing. Just the objects themselves.  There is no drag preview.  If you want to insert and drag, you must.

 

1)Insert the external block as normal without exploding.

2)Explode the block.

3)Decide whether the block definition should be deleted.

 

OR

 

1)Have a program do the insert/explode and choose the point automatically (perhaps 0,0,0) instead of allowing the user to select the insertion point.

2)Select the objects just placed and start the move command.  The program enters the first point as the basepoint and the pause is used by the user to drag.

 

These kinds of issues come up frequently on the newsgroup.  I would recommend that you learn how to search for the answers yourself before asking the question and then ask when those solutions don't work or need additional explanation. 

 

http://lmgtfy.com/?q=Autolisp+insert+and+explode+drag

Architect, Registered NC, VA, SC, & GA.
0 Likes