Legend Generator

Started by scottcd, April 30, 2009, 08:13:19 AM

Previous topic - Next topic

scottcd

Legend Generator
Created using Version 5.1.0.3

Still a bit rough around the edges with my programming, but thought I would share this anyway.

Error checking is fairly minimal, so use at your own risk.

Let me know what you think, and any improvements needed.

I have included a sample drawing with our standard layers and blocks - rename sample.txt to sample.dwg

Cheers
Scott   ;D

Edit: Updated lisp file - now ignores XREF layers
Edit: Sample DWG now attached



BazzaCAD

Nice work.
I've added .dwg to the allowed file formats, so you can remove the txt and upload the dwg if you like..
a.k.a.
Barry Ralphs
barryDOTralphsATgmailDOTcom

scottcd

I will add the drawing in the morning

Thanks for the complement... I know I still have a lot to learn, but am pleased with this result.

Cheers

Scott


Slavko Ivanovic

#3
good work.


I was take one look on your code, so i will give you few tips
important for your future programing.
(while I'm waiting someone and must kill some time  :))

1. in defun you are not using arguments (arguments / variables)

Never setq vars to nil on start defun (no need):
Code (autolisp) Select

(defun c:legend ()
  (setq bb nil     ; clear vars
cc nil
block_text nil
tSize 1
legend_exit nil
noncont_layer_list
nil
lylst nil
  )
...


! put your localSymbols (variables) in defun args. after /backslash (declare them only for running function):
Code (autolisp) Select

(defun myfunction (expectedarg1 expectedarg2 ... / myvar1 myvar2 ...):

in your case:
Code (autolisp) Select

(defun c:legend (/ bb cc block_test legend_exit noncont_layer_list lylst tSize)
(setq tSize 1)
...

in that case this is what is happening
- on start function all that vars are nil
   (if some of the varnames already used & have some values (globally), don't worry
    they are only temporary suppressed, and they are reassigned after function ends)
- on end function all variables are recycled or restored to previous state

2. About arguments in defun

Predict expected data (arguments) when making defun.
example of function that expect 2 arguments named x & y:
Code (autolisp) Select
(defun plus (x y / res)
  (setq res (+ x y))
)

to call that function you MUST pass 2 expected values
(note that return value of (defun function .....) expression is always
value of the LAST evaluated EXPRESSION in that function)

Code (autolisp) Select
(setq result ; remember result returned by you function
   (plus 2 4); call function with 2 & 4 as arguments
)
;; more ways to call function same function:
(setq result
   (plus (+ 2 65) (- 35 45))
)
(setq
  a 15 b 16
  result (plus a b)
)
;; .... practicly every LISPABLE way


For example this is one of myf - get enames from sset.
Code (autolisp) Select

(DEFUN $F|SS|SSET>ELIST| (@sset / elist)
(IF @sset
  (SETQ elist (VL-REMOVE-IF 'LISTP (MAPCAR 'CADR (SSNAMEX @sset))))
)
elist              ; (you can put variable on end to return list enames (last exp in function is return value of function))
)
;; but in this case u can do only this :

(DEFUN $F|SS|SSET>ELIST| (@sset)
  (VL-REMOVE-IF 'LISTP (MAPCAR 'CADR (SSNAMEX @sset)))
)



;; iex. call like this
Code (autolisp) Select
(setq alselents
  ($F|SS|SSET>ELIST| (ssget))
)


***  siCAD Solutions for AutoCAD  ***
ArchiTools l ToolsPlus l LandTools l LBE

scottcd

Thanks for the heads up.

I must admit that I have been guitly of not declaring variable local since I first started coding  ;D

I think it was because as I was learning I was looking at all the vars to see what they were returning and I just never got around to declaring them  ::)

I know it is good practice, but in the long run I have never noticed any impact on my programs.

Mind you all my programs are relatively simple.

Cheers

Scott