Lisp to insert, purge and draw multiline

Lisp to insert, purge and draw multiline

miroko
Enthusiast Enthusiast
1,325 Views
7 Replies
Message 1 of 8

Lisp to insert, purge and draw multiline

miroko
Enthusiast
Enthusiast

Hello,

 

I have a script which like to turn to the lisp.

 

scriptbegining

-insert
"c:\MULTILINE_def.DWG"
0,0

 

xplode
l

e
-purge
b
MULTILINE_def
n
MLINE
ST
tightline
S
1
J
Z

 

scriptending

 

 

 

In the middle i also like to implement forcing layer to be 'some' and then returning back to previous after command is ready.

It is probably something from this

(setq lay (getvar "CLAYER"))
  (setvar "CLAYER" "layername")

 

  (setvar "CLAYER" lay)

 

Could anyone help ?

 

Lisp will be started by button on tool palette to draw multiline with specific style on specific layer.

And since the style may not exist then first is 'inserting' to get the style, then xplode/purge the drawing_block (need not the 'empty' blocks) and then drafting multiline with some options.

 

Reason for going to lisp is that when script is loaded by tool palette then pre-set layer is ignored for some reason even ithough is chosen in the tool definition. While in script i can force layer and return back to previous layer.

 

regards

miroko

0 Likes
Accepted solutions (1)
1,326 Views
7 Replies
Replies (7)
Message 2 of 8

Kent1Cooper
Consultant
Consultant

I believe you can just add those (setq)/(getvar)/(setvar) lines into your Script at the appropriate places -- Scripts can include AutoLisp functions [maybe within certain limits, but I think it should work here].

Kent Cooper, AIA
0 Likes
Message 3 of 8

Jonathan3891
Advisor
Advisor

This is my go at it.

 

(defun c:test (/ ss old-echo item)
  (setq old-echo (getvar "CMDECHO"))
  (command "._insert" "MULTLINE_DEF" "0,0,0" "" "" "")
    (if (setq ss (ssget "_x" '((0 . "INSERT")(2 . "*MULTLINE_DEF*"))))
    (foreach item (mapcar 'cadr (ssnamex ss))
      (command "Explode" item)
      (command "-purge" "B" "MULTLINE_DEF" "N" "")
      (command "_regenall")
            )
    )
  (setq ss nil)
  (setvar "CMDECHO" old-echo)
  (princ)
)

 Did you want the block put on the layer "SOME"? I didnt quite understand what you were asking there.

 

I also didnt notice all the other stuff you want purged. You can edit what I have to include those entities.


Jonathan Norton
Blog | Linkedin
Message 4 of 8

Jonathan3891
Advisor
Advisor

To save and recall layers;

 

(setq olayer (getvar 'clayer))
(setvar 'clayer olayer)

 

To chage layer, simply creating the layer will set it current even if it already exist (Thanks Kent)

(command "_.layer" "thaw" "LAYER NAME" "m" "LAYER NAME" "LINETYPE" "COLOR" "" "")


Dont forget to add "olayer" in the what I believe is the local variables (everything in the parenthesis after the command name)


Jonathan Norton
Blog | Linkedin
0 Likes
Message 5 of 8

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:

I believe you can just add those (setq)/(getvar)/(setvar) lines into your Script at the appropriate places ....


But if you really want a command defined, it's not necessary to fully Insert the drawing that contains the Multiline Style(s) you want, and then Explode it [or Erase it] before Purging the Block definition.  You can just get to the point where it asks for an insertion point, at which time the drawing as Block definition will have been brought in, including whatever Mline Styles are used in it, and then just cancel the Insertion without going through with the rest of it.  Lightly tested:

 

(defun C:MLSIT (/ cmde clay); = Multi-Line Style Import & start Tightline
  (setq
    cmde (getvar 'cmdecho)
    clay (getvar 'clayer)
  ); setq
  (setvar 'clayer "layername")
  (setvar 'cmdecho 0)
  (command
    "._insert" "MULTLINE_DEF" nil

      ; cancels it before insertion point -- nothing to Explode, but Mline Styles have been brought in
    "_.purge" "_blocks" "MULTLINE_DEF" "_no"
  ); command

  (setvar 'cmdecho cmde)

  (command "_.mline" "_style" "tightline" "_scale" 1 "_justification" "_zero")
  (while (> (getvar 'cmdactive) 0) (command pause)); User input until finished, before resetting Layer
  (setvar 'clayer clay)
  (princ)
); defun

Kent Cooper, AIA
Message 6 of 8

miroko
Enthusiast
Enthusiast

Hello

 

Thank you Kent1Cooper and DSM_Dude.

 

I tried first the option with the following lisp:

 

 

(defun C:MLIM (/ cmde clay); = Multi-Line Style Import & start Tightline
  (setq
    cmde (getvar 'cmdecho)
    clay (getvar 'clayer)
  ); setq
  (setvar 'clayer "200-WT1")
  (setvar 'cmdecho 0)
  (command
    "._insert" "C:\\WT_MULTILINE.DWG" nil

      ; cancels it before insertion point -- nothing to Explode, but Mline Styles have been brought in
    "_.purge" "_blocks" "WT_MULTILINE" "_no"
  ); command

  (setvar 'cmdecho cmde)

  (command "_.mline" "_style" "WT" "_scale" 1 "_justification" "_zero")
  (while (> (getvar 'cmdactive) 0) (command pause)); User input until finished, before resetting Layer
  (setvar 'clayer clay)
  (princ)
); defun

 

 

It works very nice if the drawing already have this layer. But it does not if layer dont exist. This layer is defined in the drawing being inserted so I tried to move the function calling the layer after rhe insertion of block but it did not work. Probably i was inserting in wrong place.

Is it possible to move after the insertion ?

 

Another issue which I have here is that it does not go back to previous layer if i press 'escape' after drafting the multiline. Many users do so (press escape instead of enter or right click), is it possible to make it such so that even if user press escape after drafting the line so that it still comes back to previous ?

 

regards

miroko

0 Likes
Message 7 of 8

Kent1Cooper
Consultant
Consultant
Accepted solution

@miroko wrote:

.... 

It works very nice if the drawing already have this layer. But it does not if layer dont exist. This layer is defined in the drawing being inserted so I tried to move the function calling the layer after rhe insertion of block but it did not work. Probably i was inserting in wrong place.

Is it possible to move after the insertion ?

 

Another issue which I have here is that it does not go back to previous layer if i press 'escape' after drafting the multiline. Many users do so (press escape instead of enter or right click), is it possible to make it such so that even if user press escape after drafting the line so that it still comes back to previous ?

....


Those things can be done easily enough:

 

(defun C:MLIM (/ *error* cmde clay); = Multi-Line style IMport [& start WT]

  (defun *error* (errmsg); error handler

    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (prompt (strcat "\nError: " errmsg))
    ); if

    (setvar 'clayer clay)

    (setvar 'cmdecho cmde)

  ); defun -- *error*
  (setq
    cmde (getvar 'cmdecho)
    clay (getvar 'clayer)
  ); setq
  (setvar 'cmdecho 0)
  (command
    "._insert" "C:\\WT_MULTILINE.DWG" nil

    "_.purge" "_blocks" "WT_MULTILINE" "_no"
  ); command

  (setvar 'clayer "200-WT1"); moved from earlier

  (setvar 'cmdecho cmde)

  (command "_.mline" "_style" "WT" "_scale" 1 "_justification" "_zero")
  (while (> (getvar 'cmdactive) 0) (command pause))

  (setvar 'clayer clay)
  (princ)
); defun -- C:MLIM

 

[By the way, it's not necessary to include the .DWG filetype ending in the Insert command -- it won't Insert any other kind of file.]

Kent Cooper, AIA
Message 8 of 8

miroko
Enthusiast
Enthusiast

Hello

 

Thank you for this modification.

 

It is working all good.

 

Thank you for help.

 

regards

miroko

0 Likes