add parts of dwgname to dwgprops

add parts of dwgname to dwgprops

Anonymous
Not applicable
1,044 Views
8 Replies
Message 1 of 9

add parts of dwgname to dwgprops

Anonymous
Not applicable

Hello,

 

I am not familiar with LISP en basiccally familiar with VB, but with help from all you guys on differtne forums I already put together some routines to ease up my work. But now I'm stuck.

 

I'm trying to fill a part of the current drawingname into the custom props of the drawing. For example:

 

dwgname = 2002020_20200904 (first part is the project number, second part is the drawing date.

 

In the props I want to create a custom property called Projectnr, filled with (in this example) 20-02020.

 

I found a LISP:

 

(defun c:dProps (/ dProps dProp)

(vl-load-com)

(setq acadObject (vlax-get-acad-object))
(setq acadDocument (vla-get-ActiveDocument acadObject))

;;Get the SummaryInfo

(setq dProps (vlax-get-Property acadDocument 'SummaryInfo))

;; remove custom infos
(repeat (setq n (vla-NumCustomInfo dProps))
(vla-RemoveCustomByIndex dProps (setq n (1- n)))
)

;;Add an entry to the "Custom" tab
(vla-addcustominfo dProps "Projectnr" (vl-filename-base (getvar "dwgname")))

(princ)

)

 

This basically does the job but I get the full name (2002020_20200904), where I want 20-02020.

 

Am I walking in the right direction or are there better ideas?

 

0 Likes
Accepted solutions (2)
1,045 Views
8 Replies
Replies (8)
Message 2 of 9

dlanorh
Advisor
Advisor

How are you constructing the 20-2020? is it just inserting a hyphen in the first part of the drawing name or something else.

 

You can get the drawing name using (vl-filename-base (getvar 'dwgname)) without having to dive into summaryinfo

I am not one of the robots you're looking for

0 Likes
Message 3 of 9

Anonymous
Not applicable

DLANORH,

 

Thanx for your reply. 20-02020 is a project number, starting with the year, teh part behind the minus is just a number. Because in the past an number in a filename was the separator between name and extension all drawing files are named the project number (in this case 20-02020, shortened to 2002020), added with _ and the date of the drawing (as we keep all versions available. The drawing name ('project number'_'date') is manually placed.

 

In short: we manually save a drawing as 2002020_20200904, but in the custom drawing properties it must show 20-02020

0 Likes
Message 4 of 9

dlanorh
Advisor
Advisor
Accepted solution

If it was almost working the way you wanted before then try this modification

 

(defun c:dProps (/ acadObject acadDocument dProps str n )

  (vl-load-com)

  (setq acadObject (vlax-get-acad-object))
  (setq acadDocument (vla-get-ActiveDocument acadObject))

  ;;Get the SummaryInfo

  (setq dProps (vlax-get-Property acadDocument 'SummaryInfo)
        str (vl-filename-base (getvar "dwgname"))
  )

  ;; remove custom infos
  (repeat (setq n (vla-NumCustomInfo dProps))
  (vla-RemoveCustomByIndex dProps (setq n (1- n)))
  )

  ;;Add an entry to the "Custom" tab
  (vla-addcustominfo dProps "Projectnr" (strcat (substr str 1 2) "-" (substr str 3)))
  (princ)
)

 

I am not one of the robots you're looking for

0 Likes
Message 5 of 9

Anonymous
Not applicable

That's how it's done!!!Superb, just as I wanted it. I just added a 5 behind the last 3, because I just want the project number to be placed (only 20-02020, without the date), but otherwise it works as needed!

 

Now I just need to find a solution to run the LISP directly after a 'save' or 'save as'. But that can't be too difficult.

0 Likes
Message 6 of 9

dlanorh
Advisor
Advisor

@Anonymous wrote:

That's how it's done!!!Superb, just as I wanted it. I just added a 5 behind the last 3, because I just want the project number to be placed (only 20-02020, without the date), but otherwise it works as needed!

 

Now I just need to find a solution to run the LISP directly after a 'save' or 'save as'. But that can't be too difficult.


Oops, apologies re the missing 5, I think I was going to split the string when I wrote it

I am not one of the robots you're looking for

0 Likes
Message 7 of 9

dlanorh
Advisor
Advisor
Accepted solution

@Anonymous 

 

Give this command reactor a try. Worked in my tests.

 

(vlr-command-reactor "Dprops" '((:vlr-commandEnded . dprops)))

;*******************************************************
(defun dprops (reactor params / adoc dp str n)

  (cond ( (or (wcmatch (strcase (car params)) "*SAVEAS")
              (wcmatch (strcase (car params)) "*SAVE")
          )
            (setq adoc (vla-get-activedocument (vlax-get-acad-object))
                  dp (vlax-get-property adoc 'SummaryInfo)
                  str (vl-filename-base (getvar 'dwgname))
            )
            (repeat (setq n (vla-numcustominfo dp)) (vla-removecustombyindex dp (setq n (1- n))))
            (vla-addcustominfo dp "ProjectNr" (strcat (substr str 1 2) "-" (substr str 3 5)))
        )
  )
)

 

 

 

I am not one of the robots you're looking for

0 Likes
Message 8 of 9

Anonymous
Not applicable

No apologies needed, happy with the LISP!!! Adding a 5 didn't give me the headache 🙂

0 Likes
Message 9 of 9

Anonymous
Not applicable

@dlanorh:  That did the job!! Thnx!!!

0 Likes