Lisp Across Drawings

Lisp Across Drawings

gccdaemon
Collaborator Collaborator
1,693 Views
13 Replies
Message 1 of 14

Lisp Across Drawings

gccdaemon
Collaborator
Collaborator

I have an update routine (C:UPDATETEMPLATES) that copies templates from a network location to a user template folder located on their C:\ drive. The problem I keep running into is that when someone has a "new drawing" open it locks the "ACAD.DWT" in the template folder and prevents it from being updated. I have a "TEMP.DWG" in this folder that the user can open, close out of other drawings and run updatetemplates from. Can someone help me with a routine that will automate this process? Here is the process:

- User enters new update command (C:UPDATE)

- C:UPDATE opens TEMP.DWG

- Then closes all other open drawings drawings prompting to save

- Then Runs C:UPDATETEMPLATES

Andrew Ingram
Civil 3D x64 2019
Win 10 x64 Pro
Intel Xeon E5-1620
32 GB Ram
0 Likes
1,694 Views
13 Replies
Replies (13)
Message 2 of 14

Moshe-A
Mentor
Mentor

Andrew,

 

1. why users has to open acad.dwt? (they only need to create a new drawing based on acad.dwt)

2. acad.dwt is a standard autocad template file, leave it in it's origin state, it's better to create your organization template

3.  set your temp.dwt file to read only and in your lisp turn read only on\off as needed.

 

Moshe

 

 

0 Likes
Message 3 of 14

gccdaemon
Collaborator
Collaborator

I don't think you understand me.

 

If someone opens a drawing, windows locks that file from being overwritten/deleted because it's "In use". It doesn't

matter what template you use, if it's open it's locked from being replaced. Opening TEMP.DWG and closing all other drawings frees up the .dwt files for updating.

Andrew Ingram
Civil 3D x64 2019
Win 10 x64 Pro
Intel Xeon E5-1620
32 GB Ram
0 Likes
Message 4 of 14

Moshe-A
Mentor
Mentor

@gccdaemonwrote:

I don't think you understand me.

 

If someone opens a drawing, windows locks that file from being overwritten/deleted because it's "In use". - yes i know that.

 

It doesn't matter what template you use, if it's open it's locked from being replaced.

i agree that if you open a dwf\dwg file (a named file) it is locked but i do not agree if you just create a new drawing based on acad.dwt  that autocad locks acad.dwt

just created a new drawing (drawing1.dwg) and did not named it (e.g did not save it) and the acad.dwf is not locked it's true that AutoCAD create the locks file for acad.dwf in the template folder but that is only because you did not save the new  drawingX.dwg is only temporary on memory.

 

Opening TEMP.DWG and closing all other drawings frees up the .dwt files for updating. - that is true only if you had a dwf(s) opened.


maybe you have another problem like the user does not have sufficient right on temporary folder, try invoking AutoCAD with run as Administrator?

 

0 Likes
Message 5 of 14

awkeller88
Advocate
Advocate

Maybe another way of coming at the problem.

 

You can create a setup lisp that changes template location folder to your network drive.

This way the user always has the most recent template available, and you only need to run the setup.lsp once on install. Changing user access to the network drive with the templates is a good idea as well in this case, so they only have read only rights to the template.

 

If you are interested in the code I will clean mine up and post 😛

 

~Andy

0 Likes
Message 6 of 14

roland.r71
Collaborator
Collaborator

@gccdaemonwrote:

<snip>

Here is the process:

- User enters new update command (C:UPDATE)

- C:UPDATE opens TEMP.DWG

- Then closes all other open drawings drawings prompting to save

- Then Runs C:UPDATETEMPLATES


This process is actually impossible.

A (auto)lisp runs inside a drawing and can not do anything to other drawings (besides opening them), closing the drawing terminates the LISP. The exeption being with SDI mode.

 

So, you might get it to work, if you change the process to:

- User starts C:update

- c:update closes all other drawings (look into ActiveX or VBA to do that. AutoLISP can't)

- turn SDI mode on (Single Document Interface - this allows only 1 drawing to be open)

- Open temp.dwg

- update templates

 

Another way to do it, with just regular Autolisp is to have the user close all drawings & open temp.dwg, manually, before running the update.

 

- or, by using an autoloading lisp, that will execute when the file opened is "temp.dwg" (& no other drawings are open / SDI = 1)

 

...but you should actually listen to Andy (awkeller88 ) and change your template path to the network location instead of copying it all to their local c: drive, as this means you just need to update 1 file/location.

 

Keeping your standards at 1 easy to manage & backup spot, instead of all over the place. (& requires no "updating", ever)

Message 7 of 14

awkeller88
Advocate
Advocate
;; Initital Setup for Civ3d 2018
;; Created By: Andrew Keller 20180312
;; Work in progress

;; TODO:
;;	-Add template support paths
;; -Go through other files options ;; -Handle duplicate support paths ;; -Error handling (vl-load-com) ;;------------------Paths can be edited--------------------;; (setq addSupp "P:\\_CAD\\2018_support; P:\\_CAD\\2018_support\\Code; P:\\_CAD\\2018_support\\HatchPatterns; P:\\_CAD\\2018_support\\linetypes; P:\\_CAD\\2018_support\\Templates") ;;Support Paths to be added (setq addTrust "P:\\_CAD\\2018_support\\Code") ;;Trusted Paths to be added (setq addPstyle "P:\\_CAD\\2018_support\\PlotStyles") ;;Plot Styles to Be added ;;---------------------------------------------------------;; (setq acadObj (vlax-get-acad-object)) ;;Gets Autocad object (setq acadPref (vlax-get acadObj 'Preferences)) ;;Gets Preferences Object (setq acadFiles (vlax-get acadPref 'Files)) ;;Gets Files Object (setq pltStyle (vlax-get acadFiles 'PrinterStyleSheetPath)) ;;Get existing plt styles (setq pltStyle (strcat pltStyle ";" addPstyle)) ;;Add plt styles (vlax-put-property acadFiles 'PrinterStyleSheetPath pltStyle) ;;Load new plt style list (setq supPath (vlax-get acadFiles 'SupportPath)) ;;Get existing support paths (setq supPath (strcat supPath ";" addSupp)) ;;Add support paths (vlax-put-property acadFiles 'SupportPath supPath) ;;Load new support paths (if(>=(getvar "ACADVER") "19.1") (setvar "trustedpaths" (strcat (getvar "trustedpaths") ";" addTrust)) ;;Adds the trusted path );;end if (load "acad.lsp") ;;Loads the startup LISP loader (princ)

If you decide to go the network way this is my code and should get you going. I just drag and drop this LSP onto a users Civ3d environment once on initial install.

 

Note that the above code is a work in progress, and a load once application.

I recommend having the network folder limited to read only for the majority of users.

Creating a LSP named "acad.lsp" in your coding directory will be your auto-loader for other lisps (name is important). Using the visual Lisp inspector is pretty powerful for getting where you want, if you don't know how to use it here is the tutorial page I went through: http://www.afralisp.net/visual-lisp/

 

If you notice any improvements that can be made to the code give me a heads up, I am relatively new to the LISP world and would appreciate some wisdom 🙂

 

~Andy

0 Likes
Message 8 of 14

gccdaemon
Collaborator
Collaborator

I leave the files localized in case of internet outage/server down time. Our internet gets wonky when the weather gets nasty.

 

I separate out my commands. This is what I use for support paths and pipe networks. It does have to be modified per version, but that's just job security for me. Man Wink

 

(defun C:SETPATHS (/ *FP* ACVER PATH PATHS NPATHS TPATHS TRUSTED)
	(setq ACVER (substr (getvar "ACADVER") 1 4))
	(IF	(= "22.0" ACVER)
		(PROGN	(setq	*FP*	(vla-get-files  (vla-get-preferences (vlax-get-acad-object)))
				PATH	(vla-get-SupportPath *FP*)
				NPATHS	"C:\\cad standards"
				PATHS	(strcat NPATHS PATH)
				TPATHS	"C:\\cad standards")
			(vla-put-EnterpriseMenuFile *FP* "C:\\CAD Standards\\Toolbar\\kbge toolbar")
			(vla-put-CustomIconPath *FP* "C:\\CAD Standards\\Toolbar")
			(vla-put-PrinterConfigPath *FP* "C:\\CAD Standards\\Plotters")
			(vla-put-PrinterStyleSheetPath *FP* "C:\\CAD Standards\\Plotters\\Plot Styles;C:\\CAD STANDARDS\\Plotters\\Client Plot Styles")
			(vla-put-PrinterDescPath *FP* "C:\\CAD Standards\\Plotters\\PMP Files")
			(vla-put-TemplateDwgPath *FP* "C:\\CAD Standards\\Templates")
			(vla-put-QnewTemplateFile *FP* "C:\\cad standards\\templates\\acad.dwt")
			(vla-put-PageSetupOverridesTemplateFile *FP* "C:\\cad standards\\templates\\kbge-sheets.dwt")
			(vla-put-ToolpalettePath *FP* "C:\\cad standards\\Tool Palette\\ToolPalette 2015\\Palettes")
			(setenv "DGNMAPPINGPATH" "C:\\CAD Standards\\Templates")
			(setenv "SheetSetTemplatePath" "C:\\cad standards\\templates")
			(vlax-release-object *FP*)
			(SETENV "ACAD" "" )
			(PATHADD '(	"C:\\Users\\%username%\\appdata\\roaming\\autodesk\\c3d 2018\\enu\\support"
					"C:\\program files\\autodesk\\autocad 2018\\support"
					"C:\\program files\\autodesk\\autocad 2018\\support\\en-us"
					"C:\\program files\\autodesk\\autocad 2018\\fonts"
					"C:\\program files\\autodesk\\autocad 2018\\help"
					"C:\\program files\\autodesk\\autocad 2018\\express"
					"C:\\program files\\autodesk\\autocad 2018\\support\\color"
					"C:\\program files\\autodesk\\autocad 2018\\c3d"
					"C:\\program files\\autodesk\\autocad 2018\\aca"
					"C:\\programdata\\autodesk\\c3d 2018\\enu\\data\\symbols\\mvblocks"
					"C:\\program files\\autodesk\\autocad 2018\\map"
					"C:\\program files\\autodesk\\autocad 2018\\map\\bin\\fdo"
					"C:\\program files\\autodesk\\autocad 2018\\map\\en-us"
					"C:\\program files\\autodesk\\autocad 2018\\map\\support"
					"C:\\program files\\autodesk\\autocad 2018\\map\\support\\en-us"
					"C:\\program files\\autodesk\\autocad raster design 2018\\"
					"C:\\program files\\autodesk\\autocad 2018\\map\\bin\\gisplatform"
					"C:\\program files\\autodesk\\applicationplugins\\autodeskgeotechnicalmodule2018.bundle\\contents"
					"C:\\program files\\autodesk\\applicationplugins\\autodeskgeotechnicalmodule2018.bundle\\contents\\hatches"
					"C:\\program files\\autodesk\\applicationplugins\\autodeskgeotechnicalmodule2018.bundle\\contents\\hatches\\uscs"
					"C:\\program files\\autodesk\\applicationplugins\\standardsmanager2018.bundle\\contents"
					"C:\\program files (x86)\\autodesk\\applicationplugins\\autodesk appmanager.bundle\\contents\\resources"
					"C:\\program files (x86)\\autodesk\\applicationplugins\\autodesk appmanager.bundle\\contents\\windows\\2018"
					"C:\\program files (x86)\\autodesk\\applicationplugins\\autodesk featuredapps.bundle\\contents\\resources"
					"C:\\program files (x86)\\autodesk\\applicationplugins\\autodesk featuredapps.bundle\\contents\\windows\\2018\\win64"))
			(PATHADD '(	"C:\\cad standards"
					"C:\\cad standards\\shx"
					"C:\\cad standards\\toolbar"))
			(princ "\nSupport Paths updated")
			(defun SetAeccSharedContentPath (v)
				(vl-load-com)
				(vl-registry-write (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\Profiles\\" (vla-get-activeprofile (vla-get-profiles (vla-get-preferences (vlax-get-acad-object)))) "\\Preferences\\AeccUiNetwork120") "SharedContentPath" v))
			(defun SetUSImperialPipes (v)
				(vl-load-com)
				(vl-registry-write (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\Profiles\\" (vla-get-activeprofile (vla-get-profiles (vla-get-preferences (vlax-get-acad-object)))) "\\Preferences\\AeccUiNetwork120") "16C49365-B844-484b-92CE-9A8ACE681B57" v))
			(defun SetUSImperialStructures (v)
				(vl-load-com)
				(vl-registry-write (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\Profiles\\" (vla-get-activeprofile (vla-get-profiles (vla-get-preferences (vlax-get-acad-object)))) "\\Preferences\\AeccUiNetwork120") "DCE203A2-D381-466f-A23E-08A9D9F8FDBD" v))
			(defun SetMetricPipes (v)
				(vl-load-com)
				(vl-registry-write (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\Profiles\\" (vla-get-activeprofile (vla-get-profiles (vla-get-preferences (vlax-get-acad-object)))) "\\Preferences\\AeccUiNetwork120" ) "F670B5B9-DA12-476d-B461-4FB5C5650A82" v))
			(defun SetMetricStructures (v)
				(vl-load-com)
				(vl-registry-write (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\Profiles\\" (vla-get-activeprofile (vla-get-profiles (vla-get-preferences (vlax-get-acad-object)))) "\\Preferences\\AeccUiNetwork120") "F1FEBE2D-D589-4f85-BF8E-650ED06A5EA5" v))
			(SetAeccSharedContentPath "C:\\CAD Standards\\Pipe Networks\\Pipes Catalog\\Aecc Shared Content")
			(SetUSImperialPipes "C:\\CAD Standards\\Pipe Networks\\Pipes Catalog\\US Imperial Pipes\\US Imperial Pipes.apc")
			(SetUSImperialStructures "C:\\CAD Standards\\Pipe Networks\\Pipes Catalog\\US Imperial Structures\\US Imperial Structures.apc")
			(SetMetricPipes "C:\\CAD Standards\\Pipe Networks\\Pipes Catalog\\Metric Pipes\\Metric Pipes.apc")
			(SetMetricStructures "C:\\CAD Standards\\Pipe Networks\\Pipes Catalog\\Metric Structures\\Metric Structures.apc")
			(command "PARTCATALOGREGEN" "PIPE" "STRUCTURE" "")
			(princ "\nPipe Catalog Set")
			(princ)
	)	)
	(princ)
)
Andrew Ingram
Civil 3D x64 2019
Win 10 x64 Pro
Intel Xeon E5-1620
32 GB Ram
0 Likes
Message 9 of 14

DannyNL
Advisor
Advisor

One thing I don't understand and don't get me wrong because I love to do LISP; why change profile paths with LISP?

 

Just create a new separate profile with a new name and set all the right paths, export this new profile and let users import and activate this new profile one time. Or even better, create an additional shortcut to launch AutoCAD and import/activate the profile.

 

LISP is really nice for repetitive tasks but a bit overkill for just one time actions.

0 Likes
Message 10 of 14

awkeller88
Advocate
Advocate

If you have a unreliable server and you want to localize everything but still update automatically, you could use a setup routine like the one I posted above, but just one trusted file support path with a network location for 'acad.lsp' that would load your localization routine. Acad.lsp will run automatically on startup as long as it is in the file support paths. This would allow you to update over the network but have everything saved locally so server down time will just delay the update.

 

Also, this gives you the benefit of asking if someone has turned AutoCad off and then on again when they are wondering about updates.

 

~Andy

0 Likes
Message 11 of 14

roland.r71
Collaborator
Collaborator

@DannyNLwrote:

One thing I don't understand and don't get me wrong because I love to do LISP; why change profile paths with LISP?

 

Just create a new separate profile with a new name and set all the right paths, export this new profile and let users import and activate this new profile one time. Or even better, create an additional shortcut to launch AutoCAD and import/activate the profile.

 

LISP is really nice for repetitive tasks but a bit overkill for just one time actions.


I can give you at least 1 reason:

At my current client company, the profile is created and maintained by a "3rd party". (within the company)

On installation THEY determine what you get & where it goes. When THEY change something, it gets 'distributed' automatically (& for acad, they set it as active profile)

 

THEY don't listen to us & we have no rights to add or change it. Although i can manually change the profile or even copy the profile and change that, my change is only temporary & i have to redo 'm all, after each update.

(making a "one time action" suspiciously repetitive 😛 )

 

For example: it took a year moving heaven and earth, to have them add the sheetnumber to the titleblock as a field, retrieving the layoutname (= sheetnumber) so we didn't have to add it manually... (as they also maintain the 'companies' titleblock)

 

...so, i just create lisps to do these kind of things ourselves, without banging my head to a wall all the time.

 

To get what i (& all other engineers here) want, LISP is the only way.

0 Likes
Message 12 of 14

DannyNL
Advisor
Advisor

@roland.r71wrote:


I can give you at least 1 reason:

At my current client company, the profile is created and maintained by a "3rd party". (within the company)

On installation THEY determine what you get & where it goes. When THEY change something, it gets 'distributed' automatically (& for acad, they set it as active profile)

 

THEY don't listen to us & we have no rights to add or change it. Although i can manually change the profile or even copy the profile and change that, my change is only temporary & i have to redo 'm all, after each update.

(making a "one time action" suspiciously repetitive 😛 )


 Well, in my company I'm the one supporting all the AutoCAD users and maintaining all the different client environments. And also I do get requests directly from users to make modifications to templates, blocks, etc. that I need to decline.

 

With AutoCAD you have personal user settings that do not affect the drawings and you have drawings settings that do. So changes to a title block is usually part of our clients standardization and I cannot make changes to it whenever any user or I please, without the consent of the client. I can absolutely agree with my user that such a block can or even need to be improved, but my hands are tied without direct input and approval from our client. And as we have dozens of clients I'm also maintaining the same number of AutoCAD environments within my company, that I cannot make any changes in myself that may modify how the drawings are created in anyway.

 

However, the supporting group within a company should stick and limit itself to maintaining only the necessary settings to adhere to the client or company standards without limiting the user to make personal changes that do not conflict with those standards. And resetting those settings each day falls into limiting the user in my opinion.

 

But instead of working against each other, you probably should sit down and discuss where to make the split between user settings and company settings and let them implement it. I'm assuming you all work to get the best results for your company and need to work together to achieve that.

Also IT works for and supports it's users and not the other way around. That said, also don't be unreasonable by demanding that you want to be able to change anything you like as that will never happen. Client and/or company standards will need to be met and no user should be able to make any changes to that by him or herself.

 

If you want to make changes to a title block like adding a field for the sheet number, state your case why you want that (i.e. possible error reduction compared to manually type in the sheet number and less work), get the necessary approval if needed from your manager and make them change the title block accordingly.

 

Just my 2 cents.

0 Likes
Message 13 of 14

roland.r71
Collaborator
Collaborator

We could have a long discussion about that, but as i said, me & everybody else at my department (including the head) are tired of banging our heads to walls. It's actually 2 companies (or was) 1 is the "asset owner" the other is the "asset manager" (thats us).

 

We are talking about people who don't know a darn thing about electrical engineering. (but thats 100% of their work). They are the reason we are using plain AutoCAD to begin with. they actually trew out ruplan & elcad, because: "to expensive"....

 

Officially there is nobody to create blocks, manage standards, write lisp, manage toolpalettes, etc. etc.

Which is all just plain nutts. (so we do it ourselves, between the job)

 

Replacing a suppliers titlebox for the companies titlebox, creating cable lists, creating terminallist, BOM, etc, its all done by hand... (if it wasn't for me writing lisp & my colleague creating dynamic blocks & toolpalettes)

 

You ask for a screwdriver to fasten a screw & they give you a hammer. You keep asking for a screwdriver, again and agian, but they refuse. A hammer will suffice (so they think). What do you do? Right, you go and get that screwdriver yourself.

0 Likes
Message 14 of 14

DannyNL
Advisor
Advisor

That makes it pretty difficult I can imagine.

 

But money is usually a good starting point to get things done.

Build a business case with how much drafting is costing now with all the limitations and scrappy support and how much it will cost by investing in the right software and support. Try to change short term vision to long term vision.

 

Bring this to the attention of your CEO and/or CFO and usually things should start happening if they realize they are losing massive amounts of money by continuing in the current situation.

 

BTW, I'm not into ruplan or elcad so I've no idea if it will fit your engineering workflow, but the latest AutoCAD version includes the use of the electrical toolset.

0 Likes