Keeping standard layers from being purged through lisp

Keeping standard layers from being purged through lisp

Anonymous
Not applicable
1,008 Views
18 Replies
Message 1 of 19

Keeping standard layers from being purged through lisp

Anonymous
Not applicable

We have a drawing that contains our standard layers. We call this drawing "XPLAN.dwg". This gets referenced into an architectural floor plan,civil plan,etc. I have these same layers in the floor plan so in other words i would have "A-GLAZ-EXST" & "XPLAN|A-GLAZ-EXST" In the floor plan. Viewports are set up that contain these layers "both the plan & xplan layers. The problem i am having is that people are purging layers that i dont want purged. It was suggested to me to either create points on the layers or to add xdata to layer 0. Im not sure how to start. Should i build a layer list through tablenext or is there a way to add the points into every layer in the template drawing. I would like the points to be at 0,0 i guess & to be on top of each other.I might need a little direction because im not sure how to go about creating this layer list & have a routine insert the point on every layer in my template. I will post my template file.

0 Likes
Accepted solutions (1)
1,009 Views
18 Replies
Replies (18)
Message 2 of 19

Kent1Cooper
Consultant
Consultant

As long as no one gets into the XPLAN drawing itself and Purges Layers there, those Xref-dependent Layers shouldn't go missing, because people can't Purge Xref-dependent Layers from the drawings into which XPLAN is Xref'd, even if they have nothing drawn on them in XPLAN.dwg.  As for the non-Xref-dependent Layers, I would try this:  Have nothing actually drawn in that XPLAN drawing, but just the Layers [and whatever else you may need in all such drawings, like Text and Dimension Styles, maybe some Block definitions, etc.].  Put something into the acaddoc.lsp file that Inserts that drawing with the asterisk prefix so it's pre-Exploded, meaning there won't be any need to Erase it and Purge its definition.  It will be Inserted every time a drawing is opened, bringing with it any standard Layers [etc.] that may have been Purged before.  That won't prevent people from Purging Layers, but their doing so won't survive getting out of the drawing, because when anyone gets back into it, those Layers will be restored.

Kent Cooper, AIA
0 Likes
Message 3 of 19

Anonymous
Not applicable

@Kent1Cooper wrote:

As long as no one gets into the XPLAN drawing itself and Purges Layers there, those Xref-dependent Layers shouldn't go missing, because people can't Purge Xref-dependent Layers from the drawings into which XPLAN is Xref'd, even if they have nothing drawn on them in XPLAN.dwg.  As for the non-Xref-dependent Layers, I would try this:  Have nothing actually drawn in that XPLAN drawing, but just the Layers [and whatever else you may need in all such drawings, like Text and Dimension Styles, maybe some Block definitions, etc.].  Put something into the acaddoc.lsp file that Inserts that drawing with the asterisk prefix so it's pre-Exploded, meaning there won't be any need to Erase it and Purge its definition.  It will be Inserted every time a drawing is opened, bringing with it any standard Layers [etc.] that may have been Purged before.  That won't prevent people from Purging Layers, but their doing so won't survive getting out of the drawing, because when anyone gets back into it, those Layers will be restored.


The thing is they are going into the xplan & purging layers. We use a template file that has all the layers in it. This drawing gets copied into every project directory & becomes the xref for every porject. In this file we have walls, windows,doors ,etc. When you open up the architectural floor plan drawing you see for instance "A-DOOR-EXT-NEW" as well as XPLAN|A-DOOR-EXT-NEW. If for instance in a particular project we dont have any new exterior doors & someone runs the purge command those layers are removed. My viewports are set up either to freeze or thaw that particular layer. When someone purges this layer the viewports get messed up & i have to reset them. I want the viewports to remain the same & have the exact layers in them no matter what project is being worked on. My idea was to write a lisp routine that will open up this template file & insert a point at 0,0 for every layer that is in the template but i am a little foggy on database manipulation. Here is what i have so far. i could manually open up the drawing & then run the routine but i was trying to learn how to do this from within another drawing with something like findfile or something. The drawing would be on our network so it would be something like

 

(findfile "H:\\Overlays\\client\\XPLAN.dwg")

 

then open up the drawing & create a list of all the layers in the drawing & put a point on all of the layers at 0,0

 

 

(defun C:LAYRLST()
(setq all_layers (tablelist "LAYER"))
(mapcar 'add_list all_layers)
(foreach n '(all_layers)
(command "point" 0,0)
);end foreach
);end DEFUN

 

or something like this (although im not sure how to get into a specific drawing):

(vl-load-com)

(setq acad (vlax-get-acad-object))
(setq layers (vla-get-layers (vla-get-activedocument acad)))
(vlax-for eachLayer layers
(princ (vla-get-name eachLayer))
(terpri)
)

 

I guess i ned some help on database manipulation. What i want to do is open up this drawing either with lisp or manually, get a list of all the layers & put a point on each at 0,0. but i am unsure how to write the code to do this.

0 Likes
Message 4 of 19

hmsilva
Mentor
Mentor

@Anonymous wrote:
...
 My idea was to write a lisp routine that will open up this template file & insert a point at 0,0 for every layer that is in the template but i am a little foggy on database manipulation. Here is what i have so far. i could manually open up the drawing & then run the routine but i was trying to learn how to do this from within another drawing with something like findfile or something. The drawing would be on our network so it would be something like

(findfile "H:\\Overlays\\client\\XPLAN.dwg")

...

I guess i ned some help on database manipulation. What i want to do is open up this drawing either with lisp or manually, get a list of all the layers & put a point on each at 0,0. but i am unsure how to write the code to do this.


Maybe something like this

 

;; Usage
;; (mk_pts "H:\\Overlays\\client\\XPLAN.dwg")
(vl-load-com)
(defun mk_pts (Dwg / Dbx Id Ms Pt)
  (if (findfile Dwg)
    (progn
      (setq Id (strcat "objectdbx.AxDbDocument." (substr (getvar "acadver") 1 2)))
      (setq Dbx (vlax-create-object Id))
      (vla-open Dbx Dwg)
      (setq Ms   (vla-get-modelspace Dbx)
            Lays (vla-get-layers Dbx)
      )
      (vlax-for Lay Lays
        (setq Pt (vla-addpoint Ms (vlax-3d-point '(0.0 0.0 0.0))))
        (vla-put-layer Pt (vla-get-name LAy))
      )
      (vla-saveas Dbx Dwg)
      (vlax-release-object Dbx)
    )
    (prompt (strcat ">>> " Dwg " was not found... "))
  )
  (princ)
)

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 5 of 19

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:


The thing is they are going into the xplan & purging layers. We use a template file that has all the layers in it. This drawing gets copied into every project directory & becomes the xref for every porject. In this file we have walls, windows,doors ,etc. When you open up the architectural floor plan drawing you see for instance "A-DOOR-EXT-NEW" as well as XPLAN|A-DOOR-EXT-NEW. ....


Make a .DWG file equivalent to that template file, don't tell anyone what it's called or where it lives so they won't get into that one and mess with it, and have acaddoc.lsp Insert it every time a drawing is opened as described above.

Kent Cooper, AIA
0 Likes
Message 6 of 19

mdhutchinson
Advisor
Advisor

sovby...

Are you in vinilla AutoCAD... or is it one of the verticals... like MEP or Architecture?

0 Likes
Message 7 of 19

Anonymous
Not applicable

Vanilla autocad. Currently running 2014. I'm still a little foggy on how to open up drawings & manipulate the tables, dictionairies, etc. I'm in the process of trying to learn that. I've recently been trying to learn c## programming because somebody told me online that it might help me understand things like classes,object arx, etc. I want to learn dot net also which is another reason i'm trying to learn c##. It's hard to find the time though so it's a slow process.

0 Likes
Message 8 of 19

Anonymous
Not applicable

Thanks, do i have to be in the xplan drawing to run this or will this open the xplan drawing?

0 Likes
Message 9 of 19

hmsilva
Mentor
Mentor

@Anonymous wrote:

Thanks, do i have to be in the xplan drawing to run this or will this open the xplan drawing?


You're welcome, sovby!

 

You can't be in XPLAN, nor XPLAN can't be open.

Using ObjectDBX, the target dwg, can't be open.

In a different dwg, load the code and run it, the XPLAN.dwg will be opened and processed in background.


Hope this helps,
Henrique

EESignature

0 Likes
Message 10 of 19

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:
..... My idea was to write a lisp routine that will open up this template file & insert a point at 0,0 for every layer that is in the template .... The drawing would be on our network so it would be something like 

(findfile "H:\\Overlays\\client\\XPLAN.dwg")

 

then open up the drawing & create a list of all the layers in the drawing & put a point on all of the layers at 0,0

....


Two difficulties I see with that approach.  You would need to overtly run it within every project you have, if I'm correct in assuming that the \\client\\ part above represents different Client or project folders.  And doing it by placing Point entities is still subject to the possibility that someone will Erase the Points, and then they can Purge the Layers.  Then, to correct for that, you would need to run the routine again [and you would need some way to know that it's necessary to do so].

 

But if you do what I've suggested elsewhere, every time any drawing is opened, in any project, all those Layers will be in it, regardless of anything any User might do.  The only time any will ever be missing is between the time someone Purges them and when they close the drawing.  The Layers will return when it's opened again, automatically.  You don't need to do anything at all after having put the Insertion in acaddoc.lsp.

Kent Cooper, AIA
0 Likes
Message 11 of 19

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:
....The thing is they are going into the xplan & purging layers. .....

And another thing....  If that's what's happening, I think [correct me if I'm wrong] hmsilva's approach won't help, because it looks like it puts Points on all the Layers that are in that drawing.  That won't do it on Layers that someone has already Purged, so it won't provide any "protection" except perhaps against someone Purging even more Layers [but still subject to the second issue described in my previous Reply].  I suspect you would need a list of standard Layer names coming from outside that drawing.

 

Another suggestion:  Can you administratively just deny access to that drawing except for people you trust to leave its Layers alone, so other Users can't be naughty like that?

Kent Cooper, AIA
0 Likes
Message 12 of 19

hmsilva
Mentor
Mentor

@Kent1Cooper wrote:
.. hmsilva's approach won't help, because it looks like it puts Points on all the Layers that are in that drawing.  ...

Just showed to OP one way to achieve OP's goal

 


@Anonymous wrote:

...

I guess i ned some help on database manipulation. What i want to do is open up this drawing either with lisp or manually, get a list of all the layers & put a point on each at 0,0. but i am unsure how to write the code to do this.


I'm not saying that your advice is not a valid one, your advices are always valid.

I was just showing how we could add a point in each layer in a closed dwg...

 

I don't like to use 'acaddoc.lsp' or a reactor to force some 'standard', because in my case, I produce various types of work/dwg's with different standards, and I wouldn't like to open, do some work, save and close my dwg, and add lots of layers, blocks, text/dim styles, etc, with no need, I prefer to call a routine that will create my standards on demand, even if it just insert an exploded block.

 

Henrique

EESignature

0 Likes
Message 13 of 19

Anonymous
Not applicable

Our template drawing is actually a ".dwg" drawing. Maybe i should not have referred to it as a template. Its a blank drawing that only has layers in it. There are not supposed to be any text styles or dimension styles because it is strictly for line work such as walls, doors, windows, etc. The only thing it would have set up would be system variables or something like that. It has all of our standard layers. This drawing gets copied from our network to every project that we do regardless of client. My thought was to have entities on every layer such as a point so that if they purge those layers would remain. I realize if they delete the block they will be able to purge the layers but i doubt that most of them will even notice it. I could even explain to them what it is & tell them not to delete it. Most likely anything i do wont be 100% fool proof. Sometimes we may get additional files from clients that get imported into the copied xplan drawing which if the user purges those layers its not a problem. If i do as you suggest & have a block insert in everytime someone opens a drawing i assume i will still need to have entities on every layer. Also, i still will have the problem of if someone purges the drawing & exits out the viewports get messed up because when those layers get added back in they might need to get turned on or off in various viewports. I have created layer states so this can be fixed rather easy as long as i know it needs to be fixed but since we have about 10 users working on these projects i might not even find out about it until someone notices it & if its the boss i usually get blamed for this.


@Kent1Cooper wrote:

@Anonymous wrote:
....The thing is they are going into the xplan & purging layers. .....

And another thing....  If that's what's happening, I think [correct me if I'm wrong] hmsilva's approach won't help, because it looks like it puts Points on all the Layers that are in that drawing.  That won't do it on Layers that someone has already Purged, so it won't provide any "protection" except perhaps against someone Purging even more Layers [but still subject to the second issue described in my previous Reply].  I suspect you would need a list of standard Layer names coming from outside that drawing.

 

Another suggestion:  Can you administratively just deny access to that drawing except for people you trust to leave its Layers alone, so other Users can't be naughty like that?


 

0 Likes
Message 14 of 19

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... If i do as you suggest & have a block insert in everytime someone opens a drawing i assume i will still need to have entities on every layer. Also, i still will have the problem of if someone purges the drawing & exits out the viewports get messed up because when those layers get added back in they might need to get turned on or off in various viewports. ....


No, it wouldn't need objects drawn on all Layers.  It will bring the Layers in even without that.  [And I'm not suggesting inserting it as a Block, just Inserting it pre-Exploded, so there's no Block definition involved in the target drawing, and when done more than once you don't get multiple Insertions of such a thing that can't be erased because there's nothing to select them by.]

 

But your issue about Viewports' Layer controls is a good point, and wouldn't be solved by my suggestion.

Kent Cooper, AIA
0 Likes
Message 15 of 19

Anonymous
Not applicable

One thing about your routine that i am not clear on. how does autocad know where to get that file. You are defining a function "mk_pts" & then you list some variables. then you say (if (findfile Dwg). how does autocad know where to look for "H:\\Overlays\\client\\XPLAN.dwg"? you have this commented out.

;; (mk_pts "H:\\Overlays\\client\\XPLAN.dwg")
0 Likes
Message 16 of 19

hmsilva
Mentor
Mentor
Accepted solution

@Anonymous wrote:

One thing about your routine that i am not clear on. how does autocad know where to get that file. You are defining a function "mk_pts" & then you list some variables. then you say (if (findfile Dwg). how does autocad know where to look for "H:\\Overlays\\client\\XPLAN.dwg"? you have this commented out.

;; (mk_pts "H:\\Overlays\\client\\XPLAN.dwg")

sovby,

 

'mk_pts' it's a function and expects an argument, a file path, was made to be called by another function.

i.e.

(defun c:demo nil
  (mk_pts "H:\\Overlays\\client\\XPLAN.dwg")
  (princ)
)

 or alternatively as a command

(vl-load-com)
(defun c:demo (/ Dbx Dwg Id Ms Pt)
  (setq Dwg "H:\\Overlays\\client\\XPLAN.dwg")
  (if (findfile Dwg)
    (progn
      (setq Id (strcat "objectdbx.AxDbDocument." (substr (getvar "acadver") 1 2)))
      (setq Dbx (vlax-create-object Id))
      (vla-open Dbx Dwg)
      (setq Ms   (vla-get-modelspace Dbx)
            Lays (vla-get-layers Dbx)
      )
      (vlax-for Lay Lays
        (setq Pt (vla-addpoint Ms (vlax-3d-point '(0.0 0.0 0.0))))
        (vla-put-layer Pt (vla-get-name LAy))
      )
      (vla-saveas Dbx Dwg)
      (vlax-release-object Dbx)
    )
    (prompt (strcat ">>> " Dwg " was not found... "))
  )
  (princ)
)

 

Hope this helps,
Henrique

 

 

EESignature

0 Likes
Message 17 of 19

Anonymous
Not applicable

yes, that makes alot more sense to me. I'm more familiar with seeing something like that. Thank you very much

0 Likes
Message 18 of 19

hmsilva
Mentor
Mentor

@Anonymous wrote:

yes, that makes alot more sense to me. I'm more familiar with seeing something like that. Thank you very much


You're welcome, sovby!

 

The advantage of writing this code as a function it's, if we need to use the same code in different dwg's, we don't need to rewrite all code, we just call the function from another code...


Henrique

EESignature

0 Likes
Message 19 of 19

Anonymous
Not applicable

Right you can do it as a sub function where you can call it even from another routine if i'm not mistaken.

0 Likes