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

loading layers from a list...

10 REPLIES 10
Reply
Message 1 of 11
Anonymous
451 Views, 10 Replies

loading layers from a list...

Hey all,

I'm looking for a way to load a predefined set of layers from a list,
like an ini file or something. Is there a way to do this and also have it
overwrite any other layers with the same name so if someone loads the
layers, changes something about them, and then reloads them, they will go
back to what they should be per the master list???

Hopefully that makes sence.... thanks all
John G.
10 REPLIES 10
Message 2 of 11
Anonymous
in reply to: Anonymous

To load layers not present, just insert a base dwg, easyest way.
If you want to redefine layers you may want to do that with a simple
routine, depends on the number of layers you use how long the prog. becomes.
A typical code line would look like this:
-LAYER;M;HATCH;C;6;
The trick is in the M from MAKE, line can be expanded to set L
(linetype), LW (lineweight) etc.

Regards,
Jan

John G wrote:
> Hey all,
>
> I'm looking for a way to load a predefined set of layers from a list,
> like an ini file or something. Is there a way to do this and also have it
> overwrite any other layers with the same name so if someone loads the
> layers, changes something about them, and then reloads them, they will go
> back to what they should be per the master list???
>
> Hopefully that makes sence.... thanks all
> John G.
Message 3 of 11
Anonymous
in reply to: Anonymous

You can import a saved layer state, which will reset colors, linetypes, etc. per that state.

If you start a drawinng from a template which has the corrrect layers already in place, this is much less of an issue.
Message 4 of 11
Anonymous
in reply to: Anonymous

Setting up a CAD Standard can help too.

--
R. Robert Bell


wrote in message news:5513275@discussion.autodesk.com...
You can import a saved layer state, which will reset colors, linetypes, etc.
per that state.

If you start a drawinng from a template which has the corrrect layers
already in place, this is much less of an issue.
Message 5 of 11
Anonymous
in reply to: Anonymous

Doesn't AutoCAD's layer states solve that problem?

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"John G" wrote in message news:5513015@discussion.autodesk.com...
Hey all,

I'm looking for a way to load a predefined set of layers from a list,
like an ini file or something. Is there a way to do this and also have it
overwrite any other layers with the same name so if someone loads the
layers, changes something about them, and then reloads them, they will go
back to what they should be per the master list???

Hopefully that makes sence.... thanks all
John G.
Message 6 of 11
Anonymous
in reply to: Anonymous

We have an old routine that does that, it looks like this:

(defun C:LoadLayers ()
(setvar "cmdecho" 0)
(grtext -2 "Searching for text file...")
(setq f (open (findfile "layers.txt") "r")
co 0
tex (read-line f)
)
(while (or (/= nil tex) (= "" tex))
(setq co (+ co 1)
tex (read-line f)
)
)
(close f)
(setq f (open (findfile "layers.txt") "r"))
(setq co (/ co 3))
(grtext -2 "Downloading...")
(repeat co
(setq lay (read-line f)
col (read-line f)
lin (read-line f)
)
(command "layer" "m" lay "c" col "" "l" lin "" "")
)
(grtext -2 "Layer scheme loaded...")
(princ)
)


The text file "layers.txt" contents one line each for the layer name,
color, and linetype, here's a little piece of it:


S-STL-COL
1
CONTINUOUS
S-CMU-WALL
4
CONTINUOUS
S-CMU-WALL-NBRG
3
CONTINUOUS


--
matthew g.

"The man who does not read good books has no advantage over the man who
cannot read them" -- Mark Twain
Message 7 of 11
Anonymous
in reply to: Anonymous

That really doesn't look much different that creating a script file that
loads the layers:
(defun c:ldlyrs () (command "_.script" "layers")(princ))

-.layer
m
S-STL-COL
c

1
lt
CONTINUOUS

m
S-CMU-WALL
c
4

lt
CONTINUOUS

m
S-CMU-WALL-NBRG
c
3

lt
CONTINUOUS



--
Bill DeShawn
bdeshawn@nospamsterling.net
http://my.sterling.net/~bdeshawn
(website link works now)

"Matthew Gonzalez" wrote in message
news:5521810@discussion.autodesk.com...
We have an old routine that does that, it looks like this:

(defun C:LoadLayers ()
(setvar "cmdecho" 0)
(grtext -2 "Searching for text file...")
(setq f (open (findfile "layers.txt") "r")
co 0
tex (read-line f)
)
(while (or (/= nil tex) (= "" tex))
(setq co (+ co 1)
tex (read-line f)
)
)
(close f)
(setq f (open (findfile "layers.txt") "r"))
(setq co (/ co 3))
(grtext -2 "Downloading...")
(repeat co
(setq lay (read-line f)
col (read-line f)
lin (read-line f)
)
(command "layer" "m" lay "c" col "" "l" lin "" "")
)
(grtext -2 "Layer scheme loaded...")
(princ)
)


The text file "layers.txt" contents one line each for the layer name,
color, and linetype, here's a little piece of it:


S-STL-COL
1
CONTINUOUS
S-CMU-WALL
4
CONTINUOUS
S-CMU-WALL-NBRG
3
CONTINUOUS


--
matthew g.

"The man who does not read good books has no advantage over the man who
cannot read them" -- Mark Twain
Message 8 of 11
Anonymous
in reply to: Anonymous

This bit of code reads INI files - I use this to set various stuff in AutoCAD.

You just need to put it in a LISP which handles the results from the INI file:

Hope its of use!

;; ------------------------------------------------------------------------------------------------------------
;;
;; INI File reader by Kevin Bell
;;
;; This program reads values from a INI file.
;;
;; Syntax: (readini
)
;;
;; Will return result from file or
;; "HEADERNOTFOUND" if header is not found in file
;; or
;; "KEYNOTFOUND" if key is not found in section
;;
;; Note: the data returned is always a string regardless of what it actually is.
;;
;; ------------------------------------------------------------------------------------------------------------





(defun ri:getdata (ri:data ri:getpos / ri:count
ri:look ri:pos ri:data ri:getpos
)

;; A routine for readini

;; This routine returns the constituent parts of a string either side of the equals sign depending on whether ri:getpos is "A" or "B"
;;
;; Eg
;;
;; (ri:getdata "INFOMATION="Something" "A")
;; will return "INFORMATION"
;;
;; and
;;
;; (ri:getdata "INFOMATION="Something" "B")
;; will return "Something"
;;

(setq ri:count 1
ri:look nil
ri:pos nil
)

(while (and (/= ri:data nil) (/= ri:count (+ (strlen ri:data) 1)))

(setq ri:look (substr ri:data ri:count 1))

(if (= "=" ri:look)
(setq ri:pos ri:count)
)

(setq ri:count (+ ri:count 1))

)

(setq ri:look "KEYNOTFOUND")

(if (and (/= ri:pos nil) (= ri:getpos "A"))
(setq ri:look (substr ri:data (+ ri:pos 1)))
)
(if (and (/= ri:pos nil) (= ri:getpos "B"))
(setq ri:look (substr ri:data 1 (- ri:pos 1)))
)

(setq ri:look ri:look)

)



(defun ri:finddata (ri:key / ri:stop2)

;; A routine for readini

;; One the Header has been found this routine looks for the key

(setq ri:stop2 nil
ri:result nil
)

(while (/= ri:stop2 "stop")

(setq ri:readinfo (read-line ri:openfile))

(if (and (/= ri:readinfo nil) (= (substr ri:readinfo 1 1) "["))
(setq ri:result "KEYNOTFOUND"
ri:stop2 "stop"
)
)

(if (and (/= ri:readinfo nil)
(= (ri:getdata ri:readinfo "B") ri:key)
)
(setq ri:result (ri:getdata ri:readinfo "A")
ri:stop2 "stop"
)
)

(if (= ri:readinfo nil)
(setq ri:result "KEYNOTFOUND"
ri:stop2 "stop"
)
)
)

(setq ri:result ri:result)

)





(defun readini (ri:stopenfile ri:header ri:key /
ri:openfile ri:header ri:result ri:stop
ri:readinfo ri:stop2 ri:result
)


;; Main routine which calls the above functions


(setq ri:openfile (open ri:stopenfile "r")
ri:header (strcat "[" ri:header "]")
ri:result "HEADERNOTFOUND"
ri:stop nil
ri:readinfo "HEADERNOTFOUND"
)

(while (/= ri:stop "stop")

(setq ri:readinfo (read-line ri:openfile))

(cond
(
(= ri:readinfo nil)
(setq ri:stop "stop")
)

(
(= ri:readinfo ri:header)
(setq ri:stop "stop")
(ri:finddata ri:key)
)

)


)

(close ri:openfile)
(setq ri:result ri:result)

)
Message 9 of 11
Anonymous
in reply to: Anonymous

Sorry - missed of the syntax - its:

(readini
)
Message 10 of 11
Anonymous
in reply to: Anonymous

mmm - it seems that when you post to this message group the square brackets are removed (they are probably thought to be HTML) - I'll try the message again with rectangular brackets:

The syntax is:

(readini [file name of INI file to read] [header value to find] [key value to find])

You obviously remove the rectangular brackets when you call the routine.
Message 11 of 11
petd
in reply to: Anonymous

is it also possible to ad a "layer-description" with the proposed routines.

Peter

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

Post to forums  

Autodesk Design & Make Report

”Boost