Jump to content
Halb10

Saveas Directory using attribute Value

Recommended Posts

Halb10

Hi,

 

is there a way to save my drawing with its name in a directory by using a Attribute value.

 

Example:

 

Drawingname: test.dwg

blockname: TitleBlock

Attribute: SF:WE

Attribute-Value: test2

 

And it should save the drawing in:

 

C:drawing/test drawing/(attribute-value)/...

 

but it should be in a dialogbox, so i can choose the specific subfolder

 

the direcotry up to the attribute-value is fix.

Share this post


Link to post
Share on other sites
Halb10

(defun c:FOO (/ LM:GetAttributeValue ss attValue)

(setvar "filedia" 0)

 (defun LM:GetAttributeValue (blk tag / val enx)
   (while
     (and
       (null val)
       (= "ATTRIB"
          (cdr (assoc 0 (setq enx (entget (setq blk (entnext blk))))))
       )
     )
      (if (= (strcase tag) (strcase (cdr (assoc 2 enx))))
        (setq val (cdr (assoc 1 enx)))
      )
   )
 )

 (if (and (setq ss (ssget "X" '((0 . "INSERT") (2 . "TitleBlock") (66 . 1))))
          (setq attValue (LM:GetAttributeValue (ssname ss 0) "SF:WE"))
     )
     (command "_saveas" "_2007" (getfiled "Speichern" (strcat "C:\\drawing\\test drawing\\(*****)" (vl-filename-base (getvar "dwgname"))) "dwg" 1)
     )

     ;(prompt (strcat "\n[Attribute Value] : " attValue))
 )
 (princ)
(setvar "filedia" 1)
)

 

got this Code. But I can't get it to work. (*****) there should be attValue.

Share this post


Link to post
Share on other sites
rlx

A couple of things , firstly , I would place the getfiled outside the command function because all error checking has to be done before you run this. Secondly , are you certain this folder always exists? Also you would need an additional "\\" between (****) and the (vl-filename-base (getvar "dwgname")) and another at the end of this same expression.

 

 (getfiled "testje" "d:\\temp\\lisp" "dwg" 0) 

is not the same as

 (getfiled "testje" "d:\\temp\\lisp\\" "dwg" 0) 

(with the \\ at the end

 

gr. Rlx

Share this post


Link to post
Share on other sites
Halb10

Ok, so something like this

 

 
(command "_saveas" "2007")
(getfiled "Speichern" (strcat C:\\drawing\\test drawing\\(attValue)\\" (vl-filename-base (getvar "dwgname"))) "dwg" 0)

 

Yes, the folder exists.

Is it possible with this kind of code to do this? Because I don't know how to get the Attribute Value in the Directory.

Share this post


Link to post
Share on other sites
rlx

untested :

 

 

(defun c:FOO (/ LM:GetAttributeValue ss attValue fol fn)
 (vl-load-com)(setvar "filedia" 0)
 
 (defun LM:GetAttributeValue (blk tag / val enx)
   (while (and (null val) (= "ATTRIB" (cdr (assoc 0 (setq enx (entget (setq blk (entnext blk))))))))
      (if (= (strcase tag) (strcase (cdr (assoc 2 enx)))) (setq val (cdr (assoc 1 enx))))))
 (if (and (setq ss (ssget "X" '((0 . "INSERT") (2 . "TitleBlock") (66 . 1))))
          (setq attValue (LM:GetAttributeValue (ssname ss 0) "SF:WE"))
   (vl-file-directory-p (setq fol (strcat "C:\\drawing\\test drawing\\" attValue)))
   (setq fn (getfiled "Speichern" (strcat fol "\\" (vl-filename-base (getvar "dwgname"))) "dwg" 1))
     )
     (command "_saveas" "_2007" fn)
 )
 (setvar "filedia" 1)
 (princ)
)

Share this post


Link to post
Share on other sites
Halb10

That works fine. Exactly what I needed.

 

Thank you rlx

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×