Jump to content

SAVEAS... a file with an ammended name, derived from an ATTRIBUTE value...


lamensterms

Recommended Posts

Hey guys,

 

I've got a routine which I've just started cobbling together from another routine (originally provided by Lee Mac). The purpose of the routine is to read an ATTRIBUTE value and SAVEAS "current file name & path" + "ATTRIBUTE value".

 

The failing code I have is:

 

(defun c:SWA     (/ )

(vl-load-com)

(setvar "cmddia" 0)
(setvar "filedia" 0)

 (if (and (setq bEnt (car (entSEL '((0 . "INSERT") (66 . 1) (2 . "A2TITLEBLOCK,A3TITLEBLOCK")))))
      (= "INSERT" (cdadr (entget bEnt))) (= 1 (cdr (assoc 66 (entget bEnt)))))
   (progn
     (setq aEnt (entnext bEnt))
     (while (= "ATTRIB" (cdadr (setq eLst (entget aEnt))))
   (cond ((= "C010000" (cdr (assoc 2 eLst)))
          (setq aREV (cdr (assoc 1 eLst))))
    ))))

(setq file (getvar "DWGNAME"))
(setq name (vl-filename-base file))
(setq drgname (strcat (getvar "dwgprefix") name "_" aREV))

(COMMAND "SAVEAS" "2010" drgname)

(setvar "cmddia" 1)
(setvar "filedia" 1)

 (princ)
)

 

 

 

Just wondering if someone wouldn't mind taking a quick look and steering me straight. I think I'm having an issue filtering the ENTSEL function (I normally work with SSGET rather than ENTSEL) and I'm not ashamed to admit I know very little of this function.

 

Any help/advice would be greatly appreciated, thanks guys.

Link to comment
Share on other sites

Hi lamensterms,

 

With regards to selection, as noted in the documentation, the entsel function will only accept a single [optional] string argument representing the selection prompt to be displayed to the user, entsel does not support the use of a filter list as used with ssget.

 

If you wanted to remain using entsel, you would need something along the following lines:

(if
   (and
       (setq ent (car (entsel "\nSelect Block: ")))
       (= "INSERT" (cdr (assoc 0 (setq enx (entget ent)))))
       (= 1 (cdr (assoc 66 enx)))
       (wcmatch (cdr (assoc 2 enx)) "A[23]TITLEBLOCK")
   )
   ...
)

However, for this task it may be easier to use a combination of the following ssget mode strings (some of which are undocumented):

 

  • "+." = Point selection mode
  • ":E" = Select everything within aperture
  • ":S" = Single selection only

I would hence suggest the following to get you started:

(defun c:swa ( / ent enx rev sel )
   (if (setq sel (ssget "_+.:E:S" '((0 . "INSERT") (66 . 1) (2 . "A[23]TITLEBLOCK"))))
       (progn
           (setq ent (entnext (ssname sel 0))
                 enx (entget ent)
           )
           (while (and (null rev) (= "ATTRIB" (cdr (assoc 0 enx))))
               (if (= "C010000" (cdr (assoc 2 enx)))
                   (setq rev (cdr (assoc 1 enx)))
               )
               (setq ent (entnext ent)
                     enx (entget  ent)
               )
           )
           (if rev
               (command "_.saveas" "2010" (strcat (getvar 'dwgprefix) (vl-filename-base (getvar 'dwgname)) "_" rev ".dwg"))
               (princ "\nAttribute \"C010000\" not found in selected block.")
           )
       )
   )
   (princ)
)

Note that the above is untested and does not account for whether the target file already exists.

Link to comment
Share on other sites

Hi Lee,

 

Thanks so much for the reply and help.

 

Just wondering, if I wanted to have the SSGET function automatically select the desired block, would it be safe (reliable) to replace (ssget "_+.:E:S"... with (ssget "X"...?

Link to comment
Share on other sites

Thanks so much for the reply and help.

 

You're most welcome.

 

Just wondering, if I wanted to have the SSGET function automatically select the desired block, would it be safe (reliable) to replace (ssget "_+.:E:S"... with (ssget "X"...?

 

Yes; however, be aware that if more than one block matches the criteria in the selection filter list, only the first block in the selection will be used by the program.

Link to comment
Share on other sites

Yes; however, be aware that if more than one block matches the criteria in the selection filter list, only the first block in the selection will be used by the program.

 

Understood, the routine is to ammend drawing (file) names based on the values of the title block. So, hopefully, there should only be one title block in each drawing.

 

Thanks again for your help Lee.

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