START LISP SCRIPT ON QNEW

START LISP SCRIPT ON QNEW

AIR_123
Collaborator Collaborator
1,297 Views
7 Replies
Message 1 of 8

START LISP SCRIPT ON QNEW

AIR_123
Collaborator
Collaborator

Hi Guys,

I have this little lisp to set author to dwgprops. How can I automate it such that when I start new drawing this lisp runs. I've tried to add it to ACADDOC, but there is no effect. Does there need to be some kind of timer to send data to DWGPROPS after drawing started and everything is loaded? Thx

 

 

(defun c:setauthorprop ()

  (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))
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (setq propvalue (vla-get-summaryinfo doc "Author"))
  (setq name (strcat propvalue ", " (getenv "USERNAME")))
  (vla-put-summaryinfo doc "Author" name)
  (princ)
)

 

0 Likes
Accepted solutions (1)
1,298 Views
7 Replies
Replies (7)
Message 2 of 8

TomBeauford
Advisor
Advisor

You've defined the function in Acaddoc.lsp but the function isn't executed.

Instead of defining a function simply execute the code you need by adding

(vl-load-com)(vla-put-Author(vla-get-summaryInfo(vla-get-activeDocument(vlax-get-acad-object)))(getenv "USERNAME"))

to the start of Acaddoc.lsp instead.

64bit AutoCAD Map & Civil 3D 2023
Architecture Engineering & Construction Collection
2023
Windows 10 Dell i7-12850HX 2.1 Ghz 12GB NVIDIA RTX A3000 12GB Graphics Adapter
0 Likes
Message 3 of 8

Moshe-A
Mentor
Mentor
Accepted solution

@AIR_123 ת

 

the lisp maybe load but the function is not execute cause it must be called 😀

add this line to bottom of your lisp file

 

(c:SetupAuthorProp)

 

Moshe

Message 4 of 8

TomBeauford
Advisor
Advisor

Consider a different approach. Our title blocks display the username of the last person who saved the drawing with the Field expression %<\AcVar LastSavedBy>%. More useful than the name of the person who just plotted the drawing.

We add %<\AcVar SaveDate \f "M/d/yyyy">% to the title blocks to show when they were last modified as well.

64bit AutoCAD Map & Civil 3D 2023
Architecture Engineering & Construction Collection
2023
Windows 10 Dell i7-12850HX 2.1 Ghz 12GB NVIDIA RTX A3000 12GB Graphics Adapter
Message 5 of 8

AIR_123
Collaborator
Collaborator

I knew it should be something simple 😉 Thx

0 Likes
Message 6 of 8

AIR_123
Collaborator
Collaborator

Thanks. Yes we have that. But I also need to know the author at initiation of the drawing and it should stay always the same.

0 Likes
Message 7 of 8

TomBeauford
Advisor
Advisor

Only set the current user if author is blank in properties so once it's set it should stay always the same with:

(if(=(vla-get-Author(vla-get-summaryInfo(vla-get-activeDocument(vlax-get-acad-object))))"")(vla-put-Author(vla-get-summaryInfo(vla-get-activeDocument(vlax-get-acad-object)))(getenv "USERNAME")))
64bit AutoCAD Map & Civil 3D 2023
Architecture Engineering & Construction Collection
2023
Windows 10 Dell i7-12850HX 2.1 Ghz 12GB NVIDIA RTX A3000 12GB Graphics Adapter
Message 8 of 8

TomBeauford
Advisor
Advisor

Your code would overwrite "Author" anytime it's run which isn't what you want to autorun.

The code in my last post would only set the current user if author is blank so it would stay always the same which is what you asked for wasn't it?

Add it to acaddoc.lsp and you're done. 

It would still add current "USERNAME" when editing template files which would leave that "USERNAME" in all drawings created with those templates.

I could modify it to check the file extension so it would only add "Author" to DWG files not DWT template files if that's what you want.

64bit AutoCAD Map & Civil 3D 2023
Architecture Engineering & Construction Collection
2023
Windows 10 Dell i7-12850HX 2.1 Ghz 12GB NVIDIA RTX A3000 12GB Graphics Adapter
0 Likes