How to make .bundle install run a command each time drawing is opened

How to make .bundle install run a command each time drawing is opened

CADdaddy.com
Collaborator Collaborator
1,650 Views
4 Replies
Message 1 of 5

How to make .bundle install run a command each time drawing is opened

CADdaddy.com
Collaborator
Collaborator

Hi all,

 

I've got a project that has one lisp function I want to run at the beginning of the session, "acad.lsp style"...and a different function that I want to run each time a document is opened, "acaddoc.lsp style". Both functions run fine when starting the session but the "per Document" code never runs when opening a new document.  Can someone help?

 

Here is my test code:

(defun c:PerSessionCommand ()
	(princ "\nAddin Per Session running...")
	(princ)
)

(defun c:PerDocumentCommand ()
	(princ "\nAddin Per Document running...")
	(princ)
)

Here are my components from PackageContents.xml

 

  <Components>
	<RuntimeRequirements  OS="Win64" Platform="AutoCAD*" SeriesMin="R20.0"  SeriesMax="R22.0" />

        <ComponentEntry
		AppName="StartupPerDocument"
		ModuleName="./Contents/testStartup.lsp"
		PerDocument="True"
		LoadOnAutoCADStartup="True">
		<Commands GroupName="StartupPerDocument">
			<Command Local="PerDocumentCommand" Global="PerDocumentCommand" StartupCommand="True" />
      		</Commands>
	</ComponentEntry>

        <ComponentEntry
		AppName="StartupPerSession"
		ModuleName="./Contents/testStartup.lsp"
		PerDocument="False"
		LoadOnAutoCADStartup="True">
		<Commands GroupName="StartupPerSession">
			<Command Local="PerSessionCommand" Global="PerSessionCommand" StartupCommand="True" />
      		</Commands>
	</ComponentEntry>
  </Components>

This is starting the session when both run fine.

Session.PNG

 

        

 

Nothing from addin runs when opening a new document.

Document.PNG

 

I must be missing something.  Right?

 

James LeVieux

0 Likes
1,651 Views
4 Replies
Replies (4)
Message 2 of 5

_gile
Consultant
Consultant

Hi,

 

Did you try to run the PerSessionCommand and PerDocumentCommand in the second drawing?

 

As far as I know: StartupCommand="True" make the command run at startup (when starting the session), but the testStartup.lsp should be load in each document because it's the default behavior for LISP applications (LoadReasons mainly apply to .NET or ObjectARX applications).

Overall you have two CompenentEntry related to the same Module (LISP file).

 

See >>here<<.

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 5

CADdaddy.com
Collaborator
Collaborator

Yes, they are both available. 

 

 

Also, regarding the way the order of execution, notice how the perDocument component entry is BEFORE the perSession component entry?  I  had to do it this way to force the perSession to run FIRST.  Just plain backwards.  I'll give a kudos to anyone who can explain the rational for that!

 

James

0 Likes
Message 4 of 5

CADdaddy.com
Collaborator
Collaborator

I never found a solutions but I did find a workaround:

 

The workaround (that works for me since I'm using cuix menus) is to execute the function in the .mnl lisp file that runs each time a menu is loaded.  This ensures that the function is always run when a new drawing is opened and after the drawing is fully initialized.

 

But this workaround brings another problem:

 

I have two separate bundle packages in the "ApplicationPlugins" folder.   Each has a separate menu with a separate .mnl file that runs a function upon opening the drawing. Each bundle works correctly when the other bundle is not present.  When both bundles are available, only one of the programs run when a new drawing is opened.

 

This is what the MNL for menu A looks like:

(defun-q S::STARTUP ( ) 
  (princ (load "MyProgramA.vlx"  "\n...Can't load MyProgramA.vlx"))
  (c:myfunctionA)
  (princ)
)

 

This is what the MNL for menu B looks like:

(defun-q S::STARTUP ( ) 
  (princ (load "MyProgramB.vlx"  "\n...Can't load MyProgramB.vlx"))
  (c:myfunctionB)
  (princ)
)

 

It appears that the S::STARTUP is never run on  program B because I can see that the menu B is loaded but I find that the functions in "MyProgramB" are not available when a new drawing is opened.  Is in not possible to have two S::STARTUP functions?

 

Any help would be much appreciated.

 

James

0 Likes
Message 5 of 5

_gile
Consultant
Consultant

No, you cannot have two S::STARTUP function, this is why, typically, the S:STARTUP function is a (defun-q ...) function so that it ca can be defined from several places:

 

In the MNL for menu A:

 

(if S::STARTUP
  (setq	S::STARTUP
	 (append S::STARTUP
		 '((princ (load "MyProgramA.vlx" "\n...Can't load MyProgramA.vlx"))
		   (c:myfunctionA)
		   (princ)
		  )
	 )
  )
  (defun-q S::STARTUP
	   ()
	   (princ (load "MyProgramA.vlx" "\n...Can't load MyProgramA.vlx"))
	   (c:myfunctionA)
	   (princ)
  )
)

 

In the MNL for menu B:

 

(if S::STARTUP
  (setq	S::STARTUP
	 (append S::STARTUP
		 '((princ (load "MyProgramB.vlx" "\n...Can't load MyProgramBB.vlx"))
		   (c:myfunctionB)
		   (princ)
		  )
	 )
  )
  (defun-q S::STARTUP
	   ()
	   (princ (load "MyProgramB.vlx" "\n...Can't load MyProgramB.vlx"))
	   (c:myfunctionB)
	   (princ)
  )
)

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes