Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

insert and explode block lisp

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
Anonymous
5596 Views, 10 Replies

insert and explode block lisp

I have a lisp where i am inserting a block and exploding it.  so what i done is put an * infront of the block o explode it.  when i insert it.  it will explode but it rotates the block slightly.  can anyone help.  see lisp below.

 

(defun C:aa()
(setvar "cmdecho" 0)
(command "-insert" "*aa" pause
(getvar "dimscale")
(getvar "dimscale")
0
)
(setvar "cmdecho" 1)
(princ)
)

 

 

 

 

10 REPLIES 10
Message 2 of 11
cadffm
in reply to: Anonymous

Set cmdecho to 1 in your lisp,

run the command and check the textscreen[F2] what happen.

 

Can you see the problem?

I guess your block aa is defined to 'scale uniformly' ? Then you will see that you put in a rotation of <whatever (getvar "dimscale") value is>

and then you fire a "0" to the commandline, what isn't a command.

 

Without you file, hard to say..

Sebastian

Message 3 of 11
dbhunia
in reply to: Anonymous

Hi,

 

Try this...... 

 

(defun C:aa()
(setvar "cmdecho" 0)
(command "-insert" "aa" pause (getvar "dimscale") (getvar "dimscale") 0)
(command "explode" (cdr (assoc -1 (entget (entlast)))));; To Explode either use this
;(command "explode" (ssname (ssget "l") 0));; Or use this (ie. to Explode)
(setvar "cmdecho" 1)
(princ)
)

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 4 of 11
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

I have a lisp where i am inserting a block and exploding it.  so what i done is put an * infront of the block o explode it.  when i insert it.  it will explode but it rotates the block slightly.  ….


 

When you INSERT something pre-exploded like that, it does not ask for both X and Y scale factors, but only for one scale factor, whether or not the Block is defined for uniform scaling.  It's taking your second scale-factor answer as the rotation angle.  Remove one of those (getvar "dimscale") entries.

Kent Cooper, AIA
Message 5 of 11
Anonymous
in reply to: cadffm

I remove the "*" and added an explode and it worked.  like below.

(defun C:aa()
(setvar "cmdecho" 0)
(command "-insert" "aa.dwg" pause
(getvar "dimscale")
(getvar "dimscale")
0
(command "explode" "last")
)
(setvar "cmdecho" 1)
(princ)
)

 

thanks for pointing me in the right direction.

Message 6 of 11
Anonymous
in reply to: dbhunia

Hi dbhunia,  yours worked great too.  I figure it out with adding a explode command.  What i am trying to do here is create a second clipboard.  Is it possible to have two commands in one lisp?  i would like to be asked the name of the block i want to use and for it to retain that next time i use autocad. so i guess one command to run the settings part as well. 

 

thanks for the help

 

Message 7 of 11
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

I remove the "*" and added an explode and it worked.  ....


 

Would you prefer to see it at dimscaled size  as you place it?  That's something that you can't  do if Inserting it pre-Exploded, so if you're going to Insert it first and then Explode it, you may as well take advantage of the option to drag it into place visually, at the intended size [and rotation].  If so, you can give it the scale before  the insertion point:

 

(defun C:aa ()
  (setvar "cmdecho" 0)
  (command

    "-insert" "aa" "_scale" (getvar "dimscale") "_rotate" 0 pause
    "explode" "last"
  )
  (setvar "cmdecho" 1)
  (princ)
)

 

And in that situation, as with Inserting pre-Exploded, it asks for only one scale.

 

I took the .dwg off the aa, because  1)  it's not needed [it won't Insert any other kind of file], and  2)  once the Block is in the drawing, when you use it again, it may as well just use it from the Block definition that's now internal to the drawing, rather than reaching outside to the drawing file again every time.

 

[And I combined the two commands into one  (command) function, which a lot of people apparently don't realize you can do.]

Kent Cooper, AIA
Message 8 of 11
dbhunia
in reply to: Anonymous

Hi,

 

As you asked.....

 


@Anonymous wrote:

Hi dbhunia,  yours worked great too.  I figure it out with adding a explode command.  What i am trying to do here is create a second clipboard.  Is it possible to have two commands in one lisp?  i would like to be asked the name of the block i want to use and for it to retain that next time i use autocad. so i guess one command to run the settings part as well. 

 

..................

 

Try this.....

 

(defun C:aa( / Blk)
(setvar "cmdecho" 0)
(or *userinput1*
(setq *userinput1* ""))
(setq *userinput1* (if (= "" (setq Blk (getstring T (strcat "\nEnter Block Name <" *userinput1* ">: "))))
      *userinput1*
Blk)
) (command "-insert" Blk pause (getvar "dimscale") (getvar "dimscale") 0 (command "explode" "last") ) (setvar "cmdecho" 1) (princ) )

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 9 of 11
Anonymous
in reply to: dbhunia

Hi dbhunia, that worked great but would it possible for it to remember the block name that was picked so i dont have to enter it everytime.  thats what i was saying about a second command for the settings.  would this require a dcl file?

Message 10 of 11
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

....  i would like to be asked the name of the block i want to use and for it to retain that next time i use autocad. so i guess one command to run the settings part as well. ....


 

For that, not just to retain it in the current editing session, probably the best thing is to use an Environment Variable, using the (setenv) and (getenv) functions.  One way, very lightly tested [EDIT the blue parts]:

(defun C:YourCommandName (/ blk)
  (while
    (and
      (= "" ; empty string [Enter]
        (setq blk
          (getstring
            (strcat
              "\nBlock name for whatever purposes this is"
              (if (getenv "YourCommandNameBlock")
                (strcat " <" (getenv "YourCommandNameBlock") ">"); then
                "" ; else -- no default offered if no prior value
              ); if
              ": "
            ); strcat
          ); getstring
        ); setq
      ); =
      (not (getenv "YourCommandNameBlock")); no prior value
    ); and
    (prompt "\nEnter not allowed --")
  ); while
  (setenv "YourCommandNameBlock"
    (if (= blk ""); Enter when allowed
      (getenv "YourCommandNameBlock"); then -- prior value
      blk ; else -- User input other than Enter
    ); if
  ); setenv
  (setvar "cmdecho" 0)
  (command
    "-insert" (getenv "YourCommandNameBlock")
      "_scale" (getvar "dimscale") "_rotate" 0 pause
    "explode" "last"
  ); command
  (setvar "cmdecho" 1)
  (princ)
); defun

"YourCommandNameBlock" is the name of the environment variable.  Unlike an AutoLisp variable, it will remain.  Its name should include some aspect or abbreviation of whatever command name you use, so that it won't accidentally have conflicts with any other environment variables you may develop.

 

Kent Cooper, AIA
Message 11 of 11
Anonymous
in reply to: Kent1Cooper

that worked awesome.   thanks so much for you help with this.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report