Author Topic: Layer Creator Project  (Read 38954 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Layer Creator Project
« on: July 02, 2008, 12:24:16 PM »
This is an idea I was pondering and thought I would write it down.
There are many Layer Creators out there but I thought this may be more versatile and
give some a chance to do some programing. I think Kerry's layer creator could be use as
part of the routine. It would be a great engine for the create part.
My idea is to have the end user create a Layer Data File, nothing new here. But to allow
the user to set the format of the data with a KEY record that the routine would use to
read the data. Also a default KEY that would be used when there was no data included
for that propriety. This would allow blank fields within each record.

I suppose you could consider this a CHALLENGE or a collaborative effort project.

Just rehashing and old idea.
Comments & suggestions welcome.

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

This is my pseudo code for the new routine.

Code: [Select]
Get a file pick from user (assume extension .lay)
Alternatly the file could be a CSV or XLS file
Read the file into a list
Find first line starting with */  and assume it is the format key data
Find the *+ Default Data record if included
Find any *- lines for LineType File Names
Assume lines starting with * or / or ; to be comment lines
Strip out any blank or * lines
Separate remaining lines into list of data using the separator character
Proceed to create the layers, maybe report on progress
Report completion of the routine

Each line could be a subroutine thus dividing up the project.

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

Format key is a method to allow the user to create a layer data file relevant to there needs
Only the layer Name is required & the order of data is left up to the user
Format key data starts with */
  Data separated with <space> characters
  Next character is the data separator, this applies to the layer data only
  Followed by the key for each column of data, this could be in any order but the layer data must follow this order
Format key Example:
*/ ; name color LineType LtFile PlotStyleName Discription

-< Properties available >-
name         
color       
Freeze       
LayerOn     
Lock         
Linetype     
lineweight   
description 
plottable   
PlotStyleName

LtFile is not a property of the Layer Object but a way to locate the Line Type file
If LtFile is included it will be the first file searched for the line type
else acad.lin or acadiso.lin will be searched next then the supplied LineType files will be searched in the order supplied.

Line Type file names line start with *-
Example:
*- MyLtFile.lin
*- CABltfile.lin

Include path if not in the ACAD search path.

Default Data is a way to set the data when none is included in the layer record
This data must be in the same order as the Format Key Data
Example:
Code: [Select]
*/ ; name      PlotStyleName color   LineType   Freeze   Lock    LayerOn
*+ Default Data    ;  Light   ;7  ; Continuous; thawed; Unlocked; on
FJ1_A-DIMS         ;  ; ; ; ; ;

Perhaps there should be a flag to update or skip existing layers of the same name.
This would likely be a global flag that applied to all layers in the data file.

Layer Data File Example:
Note that leading & trailing space characters in each field will be deleted
Blank lines will be ignored

Code: [Select]
*=====================
*  Framing Layer Data File
*=====================
* Used for residential framing plans with two stories

*- CABltfile.lin

*/ ; name      PlotStyleName color   LineType   Freeze   Lock    LayerOn
*+ Default Data    ;  Light   ;7  ; Continuous; thawed; Unlocked; on

FJ1_A-DIMS         ;  xLight  ;1  ; Continuous; thawed; Unlocked; on
FJ1_BREAKLINE      ;  Light   ;7  ; Continuous; thawed; Unlocked; on
FJ1_Beam           ;  Heavy   ;1  ; Short Dash; thawed; Unlocked; on
FJ1_Bearing Wall   ;  Medium  ;7  ; Continuous; thawed; Unlocked; on
FJ1_FINISH_TAGS    ;  xLight  ;7  ; Continuous; thawed; Unlocked; on
FJ1_Floor Joist    ;  Medium  ;3  ; CENTER2   ; thawed; Unlocked; on
FJ1_Hatch Lite     ;  xL_Scrn ;26 ; Continuous; thawed; Unlocked; on
FJ1_LEADERS        ;  xLight  ;7  ; Continuous; thawed; Unlocked; on
FJ1_LINE           ;  Medium  ;7  ; Continuous; thawed; Unlocked; on
FJ1_POLYLINE       ;  Medium  ;7  ; Continuous; thawed; Unlocked; on
FJ1_RECTANG        ;  Medium  ;7  ; Continuous; thawed; Unlocked; on
FJ1_Roof           ;  Medium  ;40 ; HDR       ; thawed; Unlocked; on
FJ1_SECTION_TAGS   ;  xLight  ;7  ; Continuous; thawed; Unlocked; on
FJ1_StrongBack     ;  Heavy   ;1  ; CENTER2   ; thawed; Unlocked; on
FJ1_TEXT           ;  Light   ;92 ; Continuous; thawed; Unlocked; on
FJ2_A-DIMS         ;  Light   ;1  ; Continuous; thawed; Unlocked; on
FJ2_BREAKLINE      ;  Light   ;7  ; Continuous; thawed; Unlocked; on
FJ2_Beam           ;  Heavy   ;12 ; Short Dash; thawed; Unlocked; on
FJ2_CIRCLE         ;  Medium  ;7  ; Continuous; thawed; Unlocked; on
FJ2_Ceiling Detail ;  Medium  ;13 ; Short Dash; thawed; Unlocked; on
FJ2_DIM            ;  xLight  ;1  ; Continuous; thawed; Unlocked; on
FJ2_ELLIPSE        ;  Light   ;7  ; Continuous; thawed; Unlocked; on
FJ2_Engineering    ;  Light   ;54 ; Continuous; thawed; Unlocked; on
FJ2_FINISH_TAGS    ;  xLight  ;7  ; Continuous; thawed; Unlocked; on
FJ2_FIRE_PROTECTION;  Light   ;7  ; Continuous; thawed; Unlocked; on
FJ2_Floor Joist    ;  Medium  ;82 ; CENTER2   ; thawed; Unlocked; on
FJ2_GOBOLT         ;  Medium  ;220; Continuous; thawed; Unlocked; on
FJ2_LEADERS        ;  xLight  ;7  ; Continuous; thawed; Unlocked; on
FJ2_LINE           ;  Medium  ;22 ; Continuous; thawed; Unlocked; on
FJ2_POLYLINE       ;  Medium  ;7  ; Continuous; thawed; Unlocked; on
FJ2_REBAR          ;  Heavy   ;7  ; Continuous; thawed; Unlocked; on
FJ2_RECTANG        ;  Medium  ;7  ; Continuous; thawed; Unlocked; on
FJ2_Roof           ;  Medium  ;13 ; HDR       ; thawed; Unlocked; on
FJ2_RoofOver       ;  Light   ;1  ; HDR       ; thawed; Unlocked; on
FJ2_SECTION_TAGS   ;  xLight  ;7  ; Continuous; thawed; Unlocked; on
FJ2_ShearWall      ;  xL_Scrn ;52 ; Continuous; thawed; Unlocked; on
FJ2_TEXT           ;  Light   ;2  ; Continuous; thawed; Unlocked; on
**  E N D   O F   F I L E
« Last Edit: July 02, 2008, 01:01:52 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: Layer Creator Project
« Reply #1 on: July 02, 2008, 12:37:18 PM »
Well as you know, I have a LayerCreation program.  I have struggled with this exact thing.  I use external files to determine the layers, etc... however if one edited the files and missed a delimeter it would screw up the works and crash autocad. (mainly because I do not check the validity of the data be fore using it :roll: Well the same can be said for the example you posted. ( the same can be said for any program which used an external file that can be edited by the user. (even XML which I thought about going that route).

My point is how do you control the info?  It would have to be checked before use, which in turns slows down the program.?

I am open for suggestions and I am willing to help in any way.

*All spelling error are free of charge*
« Last Edit: July 02, 2008, 01:03:59 PM by TimSpangler »
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

JohnK

  • Administrator
  • Seagull
  • Posts: 10603
Re: Layer Creator Project
« Reply #2 on: July 02, 2008, 12:48:15 PM »
IMO a propitiatory format can lead to mistakes from the maintainer. I believe its best to keep it as simple as possible. AutoCAD already has a standard for layer data --and everything else for that matter-- DXF codes. If you look at my own layer creator program you will notice that I keep the layer data in the native DXF format.

For example:
Code: [Select]
((0 . "LAYER") (2 . "0") (70 . 0) (62 . 7) (6 . "Continuous"))
This lends itself to smaller, cleaner, more efficient data -i.e. the use of bit codes for assoc code 62 for example.

I would also look into the speed of VL vs AL in this situation. In my procedure I went with AL because I coulnt match the speed of an AutoLisp version.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Layer Creator Project
« Reply #3 on: July 02, 2008, 01:01:18 PM »
I see you point John but if you use an editor with fixed character widths or an Xl file you eliminate the missplaced errors.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Layer Creator Project
« Reply #4 on: July 02, 2008, 01:06:06 PM »
Tim,
See the revised routine here. http://www.theswamp.org/index.php?topic=8763.msg287942#msg287942
It traps the errors when creating the layers & modifying the properties.

Additional error checks must be made in collection of the data from the file.
When an error is detected a message should be displayed as to the error & then the default  data used in place of the bad data.
If the Default data is bad then the ACAD default data would be automatically used.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

FengK

  • Guest
Re: Layer Creator Project
« Reply #5 on: July 02, 2008, 01:17:43 PM »
Alan,

IMO, using a tab-delimited format would be good because it allows user to have "," or ";" in the layer data. For example, I've written a similar tool and for each layer, there is a column for description of the layer, which may have "," or ";". The data file can be edited in Excel. Reading data from .xls file would not be hard either.

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: Layer Creator Project
« Reply #6 on: July 02, 2008, 01:44:07 PM »
Wow there are a lot of these Layer Creator routines running around lately :-o

Quote
Layer Data File

What's better than a drawing file (DWG)?  Very, very easy to manage layers in the host environment (a dwg IS a database). Besides, you can use said file with AutoCAD's built in 'Standards' software. Use ObjectDBX to import layers from the Layer Data File - lots of very simple streamlined examples floating around.  Use ObjectDBX to compare and fix Layer States between the activedocument and the Layer Data File - that would be a nightmare in a non-native file formate.  If a program needed to track layer interaction you have the ability to attach xdata to layers.  I think editing is better in AutoCAD; instead of a static notepad file full of cryptic text you get graphics, colors, linetypes, etc. in AutoCAD (well, I'm a designer so I guess I'm biased to graphics :wink:).

Before you go down this arduous road I just wanted to bring up a counter point - don't hate me!
James Buzbee
Windows 8

VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
Re: Layer Creator Project
« Reply #7 on: July 02, 2008, 01:52:05 PM »
i store all predefined layers in a dwg template, and just use dbx to import.
good thing is that layers' linetypes are imported automaticaly.
Code: [Select]
(defun ImportAllSmth

       (Smth DwgName / dbxDocObj dbxSmthObj AcadObj AcDocObj SmthCollectObj)
  (and (setq DwgName (findfile DwgName))
       (setq AcadObj (vlax-get-acad-object))
       (setq AcDocObj (vla-get-ActiveDocument AcadObj))
       (not (vl-catch-all-error-p
      (setq SmthCollectObj (vl-catch-all-apply 'vlax-get-property (list AcDocObj Smth)))
    )
       )
       (not (vl-catch-all-error-p
      (setq dbxDocObj
     (vl-catch-all-apply
       'vla-GetInterfaceObject
       (list
AcadObj
(strcat "ObjectDBX.AxDbDocument." (substr (getvar "ACADVER") 1 2))
       )
     )
      )
    )
       )
       (not (vl-catch-all-error-p
      (vl-catch-all-apply 'vla-open (list dbxDocObj DwgName))
    )
       )
       (not (vl-catch-all-error-p
      (setq dbxSmthObj (vl-catch-all-apply 'vlax-get-property (list dbxDocObj Smth)))
    )
       )
       (vlax-for LayerObj dbxSmthObj
(vl-catch-all-apply
   'vla-CopyObjects
   (list dbxDocObj
(vlax-safearray-fill
   (vlax-make-safearray vlax-vbObject (cons 0 0))
   (list LayerObj)
)
SmthCollectObj
   )
)
       )
       (not (vla-Regen AcDocObj acActiveViewport))
  )
  (mapcar (function
    (lambda (Obj)
      (and Obj (not (vl-catch-all-error-p Obj)) (vlax-release-object Obj))
    )
  )
  (list dbxSmthObj dbxDocObj SmthCollectObj AcDocObj AcadObj)
  )
)
;;;(ImportAllSmth "Layers" "vk_Standard.dwg")
« Last Edit: July 02, 2008, 01:55:51 PM by VovKa »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Layer Creator Project
« Reply #8 on: July 02, 2008, 02:28:48 PM »
Alan,

IMO, using a tab-delimited format would be good because it allows user to have "," or ";" in the layer data. For example, I've written a similar tool and for each layer, there is a column for description of the layer, which may have "," or ";". The data file can be edited in Excel. Reading data from .xls file would not be hard either.
Kelie,
You the user chooses the delimiter.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Layer Creator Project
« Reply #9 on: July 02, 2008, 02:31:42 PM »
Wow there are a lot of these Layer Creator routines running around lately :-o

Quote
Layer Data File

What's better than a drawing file (DWG)?  Very, very easy to manage layers in the host environment (a dwg IS a database). Besides, you can use said file with AutoCAD's built in 'Standards' software. Use ObjectDBX to import layers from the Layer Data File - lots of very simple streamlined examples floating around.  Use ObjectDBX to compare and fix Layer States between the activedocument and the Layer Data File - that would be a nightmare in a non-native file formate.  If a program needed to track layer interaction you have the ability to attach xdata to layers.  I think editing is better in AutoCAD; instead of a static notepad file full of cryptic text you get graphics, colors, linetypes, etc. in AutoCAD (well, I'm a designer so I guess I'm biased to graphics :wink:).

Before you go down this arduous road I just wanted to bring up a counter point - don't hate me!

Yes, but some people still prefer a text file list of layers.
This is an exercize and exchange of ideas and your is welcome too. 8-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

JohnK

  • Administrator
  • Seagull
  • Posts: 10603
Re: Layer Creator Project
« Reply #10 on: July 02, 2008, 02:33:36 PM »
Tim,
See the revised routine here. http://www.theswamp.org/index.php?topic=8763.msg287942#msg287942
It traps the errors when creating the layers & modifying the properties.

Additional error checks must be made in collection of the data from the file.
When an error is detected a message should be displayed as to the error & then the default  data used in place of the bad data.
If the Default data is bad then the ACAD default data would be automatically used.


entmake will not remake a layer if already exists, therefore less error trap required.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

GDF

  • Water Moccasin
  • Posts: 2081
Re: Layer Creator Project
« Reply #11 on: July 02, 2008, 02:33:59 PM »
Alan

*/ ; name      PlotStyleName color   LineType   Freeze   Lock    LayerOn
*+ Default Data    ;  Light   ;7  ; Continuous; thawed; Unlocked; on
FJ1_A-DIMS         ;  ; ; ; ; ;


I would add plot and noplot to the data. This data is stored in an ini file similar to your routine.


Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

JohnK

  • Administrator
  • Seagull
  • Posts: 10603
Re: Layer Creator Project
« Reply #12 on: July 02, 2008, 02:35:12 PM »
I see you point John but if you use an editor with fixed character widths or an Xl file you eliminate the missplaced errors.
*I* and *you* may use an editor but...
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10603
Re: Layer Creator Project
« Reply #13 on: July 02, 2008, 02:38:45 PM »
Alan

*/ ; name      PlotStyleName color   LineType   Freeze   Lock    LayerOn
*+ Default Data    ;  Light   ;7  ; Continuous; thawed; Unlocked; on
FJ1_A-DIMS         ;  ; ; ; ; ;


I would add plot and noplot to the data. This data is stored in an ini file similar to your routine.


Gary

...if your going to use a propitiatory format why not just use XML and allow for many possibilities?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Layer Creator Project
« Reply #14 on: July 02, 2008, 02:42:27 PM »
Alan

*/ ; name      PlotStyleName color   LineType   Freeze   Lock    LayerOn
*+ Default Data    ;  Light   ;7  ; Continuous; thawed; Unlocked; on
FJ1_A-DIMS         ;  ; ; ; ; ;


I would add plot and noplot to the data. This data is stored in an ini file similar to your routine.


Gary
You missed one of the concepts of the routine.

YOU the creator of the Data File determine the data.
You start with the layer name & then add the properties you want in the data file.
You also determine the order of the data, although logic would say put the name as the
first column and then it's up to you what comes next & what you want to include or exclude
from the data file.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.