Author Topic: dwg properties question  (Read 10045 times)

0 Members and 1 Guest are viewing this topic.

andrew_nao

  • Guest
dwg properties question
« on: July 11, 2007, 08:41:32 AM »
Hi gang,
I heard about this place from the autodesk forums but took me a while to actually come here
I asked this question over there but this place seems to be more active.

anyway if anyone has a moment or two to offer some help it would be appreciated, im trying to enter some custom info into the dwg properties
(setq dname (vl-filename-base (getvar "dwgname")))
(setq jname (vl-Filename-Base (vl-Filename-Directory (getvar "Dwgprefix"))))
(vla-AddCustomInfo si "DWG Name" dname)
(vla-AddCustomInfo si "Job No." jname)

now my question is this
when i run the lisp it will add this info.
if the custom info dwg name and job no. should happen to change when i run the lisp again, how can i get it to delete the info that is there and replace it with the new info?
also if the info doesnt change should the lisp be ran again what is the code to just skip it
is this correct? i havent tried but i have a feeling this isnt it

(if (= vla-AddCustomInfo si "DWG Name" dname)
(setq dname nil)
)

and if someone could fill me in on exactly what is the purpose of the "keywords"


ronjonp

  • Needs a day job
  • Posts: 7529
Re: dwg properties question
« Reply #1 on: July 11, 2007, 10:15:41 AM »
Andrew,

Welcome to the swamp :).

I don't think you need to clear out the old information before writing the new, the new information will overwrite the old automatically.

If you run the lisp at startup, then your drawings will automatically be updated.

Here is something to give you ideas:

Code: [Select]
(defun addsummaryinfo (/ suminfo)
  (setq suminfo (vla-get-summaryinfo
  (vla-get-activedocument
    (vlax-get-acad-object)
  )
)
  )
  (vla-put-author suminfo (getenv "username"))
  (vla-put-comments suminfo "")
  (vla-put-hyperlinkbase suminfo "")
  (vla-put-keywords suminfo "")
  (vla-put-lastsavedby suminfo (getenv "username"))
  (vla-put-revisionnumber suminfo "")
  (vla-put-subject suminfo "")
  (vla-put-title
    suminfo
    (strcat (getvar 'dwgprefix) (getvar 'dwgname))
  )
  (princ)
)
(addsummaryinfo)

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8709
  • AKA Daniel
Re: dwg properties question
« Reply #2 on: July 11, 2007, 10:43:38 AM »
Welcome Andrew
Maybe you can get a few ideas from the code behind this OpenDCL project
http://www.theswamp.org/index.php?topic=16908.msg204891#msg204891

andrew_nao

  • Guest
Re: dwg properties question
« Reply #3 on: July 11, 2007, 10:46:44 AM »
Hi Ron,
Thanks for the reply.
Although I thought it would overwrite the old info with the new,
it doesnt it just keeps adding

ronjonp

  • Needs a day job
  • Posts: 7529
Re: dwg properties question
« Reply #4 on: July 11, 2007, 10:53:30 AM »
I cannot duplicate the info getting appended. Maybe if you set the value to "" before you add the new it will not append?

Something like:

(vla-put-comments suminfo "")
(vla-put-comments suminfo "New Stuff")

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

GDF

  • Water Moccasin
  • Posts: 2081
Re: dwg properties question
« Reply #5 on: July 11, 2007, 11:13:42 AM »
Welcome to tha swamp...

Are you talking about these drawing properties?

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

andrew_nao

  • Guest
Re: dwg properties question
« Reply #6 on: July 11, 2007, 02:39:50 PM »
hi Gary,
No sir im not, im speaking about the custom properties
if you click on the custom tab in that screen shot, that is what im talking about

ronjonp

  • Needs a day job
  • Posts: 7529
Re: dwg properties question
« Reply #7 on: July 11, 2007, 03:05:46 PM »
That splains it...try (vla-removecustombykey suminfo "Job No.")

*this seems to work:

Code: [Select]
(setq suminfo (vla-get-summaryinfo
(vla-get-activedocument
  (vlax-get-acad-object)
)
      )
)
(if (vl-catch-all-error-p
      (vl-catch-all-apply
'vla-getcustombykey
(list suminfo "Job No." "123")
      )
    )
  (vla-addcustominfo suminfo "Job No." "123")
  (vla-setcustombykey suminfo "Job No." "123")
)
« Last Edit: July 11, 2007, 03:27:20 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

andrew_nao

  • Guest
Re: dwg properties question
« Reply #8 on: July 11, 2007, 03:36:55 PM »
no that did not work.

this is what i have in my lisp
im trying to get it where if this lisp is ran again on the same dwg, if the information isnt the same as is listed in the custom properties
its removed and the new information is placed in there
Code: [Select]
(vl-load-com)

(defun c:ADDPROPS (/ doc db si author dname pname)
(setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(setq db (vla-get-Database doc))
(setq si (vla-get-SummaryInfo db))
(setq lname (getvar "loginname"))
(setq dname (vl-filename-base (getvar "dwgname")))
(setq pname (vl-Filename-Base (vl-Filename-Directory (getvar "Dwgprefix"))))
(vla-put-author si lname)
(vla-AddCustomInfo si "DWG Name" dname)
(vla-AddCustomInfo si "Job No" pname)

)
(princ)

ronjonp

  • Needs a day job
  • Posts: 7529
Re: dwg properties question
« Reply #9 on: July 11, 2007, 04:22:12 PM »
Try this one...IMO, it would be much easier to add this info into the summary tab using comments since it automatically updates without having to check for existing entries.

Code: [Select]
(defun c:ADDPROPS (/ doc db si author dname pname)
  (setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
  (setq db (vla-get-Database doc))
  (setq si (vla-get-SummaryInfo db))
  (setq lname (getvar "loginname"))
  (setq dname (vl-filename-base (getvar "dwgname")))
  (setq pname (vl-Filename-Base
(vl-Filename-Directory (getvar "Dwgprefix"))
      )
  )
  (vla-put-author si lname)
  (if (vl-catch-all-apply
'vla-removecustombykey
(list si "Job No.")
      )
    (vla-addcustominfo si "Job No." pname)
    (progn
      (vl-catch-all-apply
'vla-removecustombykey
(list si "Job No.")
      )
      (vla-addcustominfo si "Job No." pname)
    )
  )
  (if (vl-catch-all-apply
'vla-removecustombykey
(list si "DWG Name")
      )
    (vla-addcustominfo si "DWG Name" dname)
    (progn
      (vl-catch-all-apply
'vla-removecustombykey
(list si "DWG Name")
      )
      (vla-addcustominfo si "DWG Name" dname)
    )
  )
)

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

BazzaCAD

  • Guest
Re: dwg properties question
« Reply #10 on: July 11, 2007, 05:41:47 PM »
Here's what I do to add custom props, w/o having to delete the key first...

Code: [Select]
  (setq NewTitle "STUFF")
  (setq App (vlax-Get-Acad-Object)
        Doc (vla-Get-ActiveDocument App)
        DwgProps (vla-Get-SummaryInfo Doc)
  )

  (setq errobj (vl-catch-all-apply 'vla-SetCustomByKey (list DwgProps "SHEET NUMBER" NewTitle)))
  (if (vl-catch-all-error-p errobj)
    (vla-AddCustomInfo DwgProps "SHEET NUMBER" NewTitle)
  );_ if


It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8709
  • AKA Daniel
Re: dwg properties question
« Reply #11 on: July 11, 2007, 10:41:54 PM »
Try something like this, if the key exists, update it else, make a new entry

Code: [Select]
(defun getCustomDwgProp (key / app counter counter2 counter3 doc dwgprops k v)
  (vl-load-com)
  (setq App (vlax-Get-Acad-Object)
Doc (vla-Get-ActiveDocument App)
DwgProps (vla-Get-SummaryInfo Doc)
counter 0
counter2 (vla-NumCustomInfo DwgProps)
  )
  (while (< counter counter2)
    (vla-GetCustomByIndex DwgProps counter 'k 'v)
    (if (eq key k)
      (setq counter3 counter)
    )
    (setq counter (+ 1 counter))
  )
  (setq k nil
v nil
  )
  (if counter3
    (vla-GetCustomByIndex DwgProps counter3 'k 'v)
  )
  (if v
    v
    nil
  )
)
;;;
(defun SetCustomDwgProp (key value / App Doc DwgProps)
  (vl-load-com)
  (setq App (vlax-Get-Acad-Object)
Doc (vla-Get-ActiveDocument App)
DwgProps (vla-Get-SummaryInfo Doc)
  )
  (if (getCustomDwgProp key)
    (vla-SetCustomByKey DwgProps key value);<--------
    (vla-AddCustomInfo DwgProps key value);<--------
  )
)
« Last Edit: July 11, 2007, 10:55:11 PM by Danielm103 »

andrew_nao

  • Guest
Re: dwg properties question
« Reply #12 on: July 12, 2007, 09:03:10 AM »
Try this one...IMO, it would be much easier to add this info into the summary tab using comments since it automatically updates without having to check for existing entries.

Ron

Ron
Thanks this is working, now i have to read it all so i can understand it
the comments would be easier but im using that for something else :)
thanks again for everyones replies

ronjonp

  • Needs a day job
  • Posts: 7529
Re: dwg properties question
« Reply #13 on: July 12, 2007, 09:15:38 AM »
Glad we got it figured out :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

andrew_nao

  • Guest
Re: dwg properties question
« Reply #14 on: July 13, 2007, 02:27:38 PM »
hi everyone more questions if anyone can help guide me

im trying to setq the custom variable
this is what i have so far.
out of the custom entry 2 lines (so far) i can only grab the last custom entry line which is "dwg name" and the actual dwg name.

can anyone point the way on how i can set the variable for the other custom entry line or lines if there should be more then just the 2 custom entries?
or am I going about this the wrong way?

Code: [Select]
(defun c:GETPROPS (/ doc db si Num Index Custom)
(setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(setq db (vla-get-Database doc))
(setq si (vla-get-SummaryInfo db))
  (setq Num (vla-NumCustomInfo SI))
  (setq Index 0)
   (repeat Num
    (vla-getCustomByIndex SI Index 'ID 'Value)
    (setq Custom (cons (cons ID Value) Custom))
    (setq Index (1+ Index))
(SETQ X ID)
(SETQ Z VALUE)
   )
  (if Custom (reverse Custom))
)