Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Creating New Layers from dialog box based on specific drawing

12 REPLIES 12
Reply
Message 1 of 13
sovby
925 Views, 12 Replies

Creating New Layers from dialog box based on specific drawing

I have a drawing that has all of the layers that i need. all of my projects use these layers but sometimes they wind up being purged from users through the design process. I have a routine that creates all of these layers from the start but i would like to create a routine that gets a layer list from this master drawing & uses a dialog box to select a layer to add in a new drawing. It would have all of the properties such as color, linetype, etc. as the master file. I based some of this on what i got off of Afralisp but i need to modify it to suit my needs. Do i have to have the routine open up the master drawing? If so do i need to add vl-load-com?I am including my lisp,dcl. 

 

 

12 REPLIES 12
Message 2 of 13
pbejse
in reply to: sovby


@sovby wrote:

I have a drawing that has all of the layers that i need. all of my projects use these layers but sometimes they wind up being purged from users through the design process. I have a routine that creates all of these layers from the start but i would like to create a routine that gets a layer list from this master drawing & uses a dialog box to select a layer to add in a new drawing. It would have all of the properties such as color, linetype, etc. as the master file. I based some of this on what i got off of Afralisp but i need to modify it to suit my needs. Do i have to have the routine open up the master drawing? If so do i need to add vl-load-com?I am including my lisp,dcl. 

 

 


It would be loads  easier to use Design Center [Ctrl+2] for this task sovby IMO.

 

If you want lisp, ---> Steal from Drawing: Lee Mac <---- [its more than just layers]

 

Or a "user" can save the layers (color/ltype...) to an external file [csv or txt] and us a  routine to read that file to build the "layer list"

 

Or use ObjectDBX to read the layers [sans opening the master dwg] to collect the layers.

 

 

Message 3 of 13
sovby
in reply to: pbejse

You are right. You can do this with design center very easily but i am trying to learn lisp so i thought it would be good practice. The only thing with using design center is that you have to go to the right file to get the layers where i was trying to have it so my routine got the layers from a certain file automatically. I was unsure how to go about getting the routine to access the file to build the layer list. We have a routine that creates all of the layers if the drawing is completely empty but i thought it would be nice to have something that adds one or two that might be missing. We would already know the name so the user would pick it from the dialog box.


@pbejse wrote:

@sovby wrote:

I have a drawing that has all of the layers that i need. all of my projects use these layers but sometimes they wind up being purged from users through the design process. I have a routine that creates all of these layers from the start but i would like to create a routine that gets a layer list from this master drawing & uses a dialog box to select a layer to add in a new drawing. It would have all of the properties such as color, linetype, etc. as the master file. I based some of this on what i got off of Afralisp but i need to modify it to suit my needs. Do i have to have the routine open up the master drawing? If so do i need to add vl-load-com?I am including my lisp,dcl. 

 

 


It would be loads  easier to use Design Center [Ctrl+2] for this task sovby IMO.

 

If you want lisp, ---> Steal from Drawing: Lee Mac <---- [its more than just layers]

 

Or a "user" can save the layers (color/ltype...) to an external file [csv or txt] and us a  routine to read that file to build the "layer list"

 

Or use ObjectDBX to read the layers [sans opening the master dwg] to collect the layers.

 

 


 

Message 4 of 13
paullimapa
in reply to: sovby

So far your lisp routine only shows lisp funtions and no visual lisp functions.  Until visual lisp functions are used (these are typically preceded with VL-, you do not need to include (vl-load-com).

Since you don't want to provide the user with the need to select the location of the drawing template that has all these layers with properties already pre-defined and you want to learn lisp, I would suggest you include the layer name creation with all the respective properties like Color & Linetype within the Lisp file.

Then you can program a DCL list box with all the Layer names for the user to do a single or multiple selection from.  When the user clicks OK the lisp routine would match the selections with an associated list of names with the respective properties inside the lisp code to create the respective layers.

How does that sound?

 

AOL @ Exchange App Store         DDSetup @ Exchange App Store


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 5 of 13
pbejse
in reply to: sovby


@sovby wrote:

You are right. You can do this with design center very easily but i am trying to learn lisp so i thought it would be good practice. The only thing with using design center is that you have to go to the right file to get the layers where i was trying to have it so my routine got the layers from a certain file automatically. I was unsure how to go about getting the routine to access the file to build the layer list. We have a routine that creates all of the layers if the drawing is completely empty but i thought it would be nice to have something that adds one or two that might be missing. We would already know the name so the user would pick it from the dialog box.

 


So you're saying the populated layer list would depend on the current layers on the Main drawing? And the "Main drawing" would depend on the project number or something to that effect?

 

That would be fun to code 🙂

 

Or are the layers on the main drawing is static? In that case you dont need to acess the "main drawing" and just use an external file [TXT/CSV] which will show a "list" of layers for you to select. you can even include a wildcard match if needed. Will that work for you?

 

 

Message 6 of 13
sovby
in reply to: pbejse

i basically have a prototype set up that has all of the layers that we use for most projects. I was thinking that i could have a lisp routine that populated the list from this drawing. I was reading up on the afralisp website & it seemed like i could get into the database of a drawing & do a tablesearch to get the list of layers to populate my dialog box.These layers usually would not change & if they do it i guess i would have to re-populate the list. It would be really cool if i could get the dialog box to change as the layers in the drawing change but for right now i am just looking to populate the list. I could like you said put them into the coding one by one if i have to. Thats how we setup our drawing initially. We have a routine that creates all of the layers in a brand new drawing. I will post it here. Oddly, im having trouble posting this file so i will try it as a txt file

Message 7 of 13
pbejse
in reply to: sovby

If you are only wanting to populate a list., you can start Here <--- link , particularly post # 8 [peter]

 

 

Holler if you hit a snag

 

HTH

Message 8 of 13
sovby
in reply to: pbejse

Thanks. i think what i need to concentrate on is the vis


@pbejse wrote:

If you are only wanting to populate a list., you can start Here <--- link , particularly post # 8 [peter]

 

 

Holler if you hit a snag

 

HTH



ual lisp commands. I found something online that i will go through but this helps also. I appreciate your help.

Message 9 of 13
sovby
in reply to: sovby

Here is an update of what i have. I'm a little stuck right now & could use some more direction. I need help on getting into the source drawing to populate my list. I'm not sure if what i have is done right. Probably not. Just a refresher, I'm looking to get all layers from a specific drawing & populate a list for a dcl file. I want to be able to pick on the name in the list & have that add the layer into the current drawing that a user has open. I guess i am also lacking an action statement to tell autocad to add the layer in once its selected & also i guess i need to add something to get the curent directory of the file that the user has open because that is where that i am adding the layers into. 

Message 10 of 13
scot-65
in reply to: sovby


@sovby wrote:

Here is an update of what i have. I'm a little stuck right now & could use some more direction. I need help on getting into the source drawing to populate my list. I'm not sure if what i have is done right. Probably not. Just a refresher, I'm looking to get all layers from a specific drawing & populate a list for a dcl file. I want to be able to pick on the name in the list & have that add the layer into the current drawing that a user has open. I guess i am also lacking an action statement to tell autocad to add the layer in once its selected & also i guess i need to add something to get the curent directory of the file that the user has open because that is where that i am adding the layers into. 


I'm thinking a different approach than to concurrently open another DWG file for layer information.

 

In my view this part of the program is set by the proprietor of the system, therefore a separate program altogether.

Write a separate program that will extract all the current layers and their properties and write to an external file.

Place this file in a common support path shared by all workstations. Secure this folder/file as needed.

When the individual starts your layer repopulating program, read from this external file.

 

The separate program should also have the capabilities of rewriting the existing external file when new layers

are added/removed to that "specific" drawing.

 

===============================

 

Another Method (I'm not keen on chasing down external files when there is a fundamental system change):

Make use of the DWG file's dictionary.

Investigate VLAX-LDATA-PUT and VLAX-LDATA-GET.

 

Create a 2 dimension LIST (a list of lists) for each layer and their properties and embed into the template:

 

(vl-load-com)

(vlax-ldata-put "MyLayers" "MyList" (list

 (list "0" "7" "phantom")

 (list "Defpoints" "11" "continuous")

 (list "F1wall" "6" "hidden")

 ...etc.

))

 

To access the list, use NTH:

(setq a (vlax-ldata-get "MyLayers" "MyList"))

(nth 2 (nth 1 a)) will return "continuous" as lists are zero based (first position is 0).

 

You will find that gathering/saving the layer names (/data) for the DCL using lists is easier than envisioned.

 

I could expand more on this topic, just let me know (especially data handling and program architecture for the DCL).

 

???

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 11 of 13
sovby
in reply to: scot-65

Yeah, thanks. I will read up on those functions. I think what you are saying is write the layers to an ascii file using another program. Then use my layer populating program to read from that file to populate my dialog box. Can my lisp routine read that from another lisp file? The reason i ask is because we have another lisp program that is a list of our layers that we use if the drawing is totally blank. This routine will create all new layers. Im thinking that i can use this to populate my dialog box. The way this routine works is that it reads the drawing name & uses a slightly different list say if your using an elevation drawing versus if your in an mep drawing. I'm thinking that i can have the dialog box read from the different sub routines, (if thats the proper term) within this lisp file & depending on what drawing you are in the dialog box will populate with a different list. What do you think?

Message 12 of 13
scot-65
in reply to: sovby


@sovby wrote:

Yeah, thanks. I will read up on those functions.

 

1) I think what you are saying is write the layers to an ascii file using another program. Then use my layer populating program to read from that file to populate my dialog box.

 

2) Can my lisp routine read that from another lisp file? The reason i ask is because we have another lisp program that is a list of our layers that we use if the drawing is totally blank. This routine will create all new layers.

 

2a) Im thinking that i can use this to populate my dialog box. The way this routine works is that it reads the drawing name & uses a slightly different list say if your using an elevation drawing versus if your in an mep drawing.

 

2b) I'm thinking that i can have the dialog box read from the different sub routines, (if thats the proper term) within this lisp file & depending on what drawing you are in the dialog box will populate with a different list.

 

3) What do you think?


Comment #1:

 This can be done, but I do not know how to do this.

 

Comment #2:

 No need to. I'm thinking you will first use TBLNEXT to create a list of all the layer names in a particular file, sort this list, then

loop the list using FOREACH, and inside use TBLSEARCH to gather the physical properties of the layer (color, linetype, etc.).

[Be careful with the TBLSEARCH as DXF 62 controls not only the color number, it also controls the On/Off state of that layer]

 

Comment #2a:

 By storing the layer list as suggested in the second half of my previous message using VLAX-LDATA-PUT, you would actually

store two lists - One for elevation, the other for MEP. You can use the drawing name to identify which list to populate from, or

create a "pre" dialog box with two simple radio buttons and the OK/Cancel to begin (set up both just in case).

 

Comment #2b:

 This cannot be done in this manner.

Envision the following: Populate a blank drawing with the "other" program. Set up the "administrator" routine to write to the dictionary

one group of layers. Purge out the layers and populate the blank drawing with the other half of the "other" program. Repeat write

to dictionary using a different key. Now you have two lists stored in the dictionary, inside that blank drawing.

 

The problem begins when you have an existing file you wish to populate the dictionary with these two lists.

I would then decompile the "other" program and use the pertinent blocks of code to create the new program.

When a file is first opened, check if the dictionary has these two lists. If not, (silently) run a program that will add the lists to the file.

Keyword here is CHECK.

 

 

3: I'll let you do all the decision making - I'm just here to help you along without actually writing code (except of course snippets).

 

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 13 of 13
scot-65
in reply to: sovby

I found this snippet only after submitting my reply yesterday.
It is in regard to comment 2.
(setq layers (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))))

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost