Jump to content

Recommended Posts

Posted

Hi

somebody please help me with a lisp program, which changes the layer of all tags in an attribute block into single layer selected by the user.

Posted

Hi ,

 

Are you aware of the command battman ?

If that does not help , give more details about your goal with a sample drawing if possible .

Posted

Thanks for your reply.

 

Ya I’ve used BATTMAN command a couple of times. Using that command I can change the layer of each tags of the attribute block. But with that command we can change the layers only by selecting each tag individually. Hence if I have an attribute block with many tags, it becomes tedious.

 

But my goal is changing the layer of all tags of an attribute block into a common layer.

Posted
Ya I’ve used BATTMAN command......

...But my goal is changing the layer of all tags of an attribute block into a common layer.

 

You can however use block editor to change the layers of the tags then run Attsync.

 

Let me ask you this, Are the layers for the attribute definition varies for every drawing session? or is it a permanent layer for ALL?

Posted

Hi pBe,

I'm looking for the LISP because, this is a part of an automation process that i'm trying now.

 

Yes the layers of Attribute definition Varies for every drawing session. But in about 70% of sessions it is a single layer "Note-ref"

Posted
Hi pBe,

I'm looking for the LISP because, this is a part of an automation process that i'm trying now.

 

By automation process you mean by batch? or are you opening the file one by one?

 

Yes the layers of Attribute definition Varies for every drawing session. But in about 70% of sessions it is a single layer "Note-ref"

 

And what of the 30%? how does that come into play?

 

A lisp routine for this is easy, i'm just trying to understand the logic behind it Antas, I'm pretty sure somebody is writing a code for this as of this writing.

 

I'm just making sure i understand all the conditions before i even start to write the lisp code :)

Posted

Thanks for your interest pBe,

 

Let me explain my routine,

 

I have many sets of drawings, each set contains about 20 drawings. Each drawing contains an Attribute block.

That block usually contains up to 30 tags.

I open one drawing, and then I change the layer of all the tags of the block into single required layer by using BATTMAN or simply by double clicking the block.

 

70% means… In 7 out of 10 sets I work with, needs a layer change into a layer “Note-ref". I.e all the tags of the block is converted into “Note-ref” in most drawings.

 

Leave alone these percentages,

I hope i have clarified you.

Please ask if have to give any further info

Posted

Hi ,

 

Give this a shot and let me know :)

 

(defun c:Test (/ _doc ss name l)
;;;        Tharwat 31.12.2014        ;;
 (if
   (and
     (or
       (tblsearch "LAYER" "Note-ref")
       (progn (alert
                "Layer name < Note-ref > is not found in the drawing !!"
              )
              nil
       )
     )
     (princ "\n Select Attributed Blocks ...")
     (ssget "_:L" '((0 . "INSERT") (66 . 1)))
   )
    (progn
      (setq _doc (vla-get-ActiveDocument (vlax-get-acad-object)))
      (vlax-for s (setq ss (vla-get-ActiveSelectionSet _doc))
        (if (not (member (setq name (vla-get-effectivename s)) l))
          (setq l (cons name l))
        )
      )
      (vla-startUndomark _doc)
      (vlax-for x (vla-get-blocks _doc)
        (if (member (vla-get-name x) l)
          (vlax-for b x
            (vla-put-layer b "Note-ref")
          )
        )
      )
      (mapcar '(lambda (n) (command "_.attsync" "_name" n)) l)
      (vla-endundomark _doc)
      (if ss
        (vla-delete ss)
      )
    )
 )
 (princ)
)(vl-load-com)

Posted

This code is working nice, Tharwat

 

Could you make the code to ask the user to select the layer from the available layers in the drawing.?

Posted
This code is working nice, Tharwat

 

Could you make the code to ask the user to select the layer from the available layers in the drawing.?

 

Try this and let me know .

 

(defun c:Test (/ *error* _dialog cho _doc dlg ss name l lay)
;;;        Tharwat 31.12.2014        ;;
 (defun *error* (msg)
   (if (and dlg (findfile dlg))
     (vl-file-delete dlg)
   )
   (if cho
     (setvar 'CMDECHO cho)
   )
   (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*"))
     (princ (strcat "\n** Error: " msg " **"))
   )
   (princ)
 )
;;;                        ;;;
 (defun _dialog (/ nm id f l lay layers)
   (cond
     ((not
        (and
          (setq dlg (vl-filename-mktemp nil nil ".dcl"))
          (setq f (open dlg "w"))
          (write-line
            "options : dialog {label = \"Layers\"; height = 6;
            spacer_1 ;
            : popup_list { key = \"lst\";}
            : boxed_row {
            : button { label = \"Okay\"; key = \"oki\"; width = 12;}
            : button { label = \"Exit\"; key = \"esc\"; is_default = true; is_cancel = true; width = 12;}}}"
            f
          )
          (not (close f))
        )
      )
      (alert "Can't load the temporary file <!>")
     )
     ((or (not dlg)
          (not (> (setq id (load_dialog dlg)) 0))
          (not (new_dialog
                 "options"
                 id
               )
          )
      )
      (princ "\n Can not load Dialog !")
     )
     (t
      (while (setq l (tblnext "LAYER" (not l)))
        (if (not (wcmatch (setq nm (cdr (assoc 2 l))) "*|*"))
          (setq layers (cons nm layers))
        )
      )
      (setq layers (acad_strlsort layers))
      (start_list "lst")
      (mapcar 'add_list layers)
      (end_list)
      (action_tile
        "oki"
        "(setq lay (get_tile \"lst\"))(done_dialog)"
      )
      (action_tile "esc" "(done_dialog)")
      (start_dialog)
      (unload_dialog id)
      (vl-file-delete dlg)
     )
   )
   (if lay
     (nth (atoi lay) layers)
   )
 )
 ;;                            ;;;
 (if
   (and (setq lay (_dialog))
        (princ "\n Select Attributed Blocks ...")
        (ssget "_:L" '((0 . "INSERT") (66 . 1)))
   )
    (progn
      (setq cho  (getvar 'CMDECHO)
            _doc (vla-get-ActiveDocument (vlax-get-acad-object))
      )
      (setvar 'CMDECHO 0)
      (vlax-for s (setq ss (vla-get-ActiveSelectionSet _doc))
        (if (not (member (setq name (vla-get-effectivename s)) l))
          (setq l (cons name l))
        )
      )
      (vla-startUndomark _doc)
      (vlax-for x (vla-get-blocks _doc)
        (if (member (vla-get-name x) l)
          (vlax-for b x
            (vla-put-layer b lay)
          )
        )
      )
      (mapcar '(lambda (n) (command "_.attsync" "_name" n)) l)
      (vla-endundomark _doc)
      (setvar 'CMDECHO cho)
      (if ss
        (vla-delete ss)
      )
    )
 )
 (princ)
)(vl-load-com)

Posted

Well,

you just made my 2 tedious works into an easy one. I never thought it is easy.

 

But u simply solve it. From now i'm your fan Tharwat :thumbsup::thumbsup::thumbsup:

Posted
Well,

you just made my 2 tedious works into an easy one. I never thought it is easy.

 

But u simply solve it. From now i'm your fan Tharwat :thumbsup::thumbsup::thumbsup:

 

Thanks for the nice words Antas :)

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...