dear Kent1Cooper
Thank you very match for your help now and so many times in the past.
I downloaded the SetAs lsp file.
It's near what i want, but
1) I don't want running the command to start creating a similar object that i wish to.
I prefer, command to stop after setting the initialization system variables used as default
properties when a new object is created getting the values from the sected object's properties and nothing more.
2) Bylayer is my color and linetype option for all objects, so, initializing must reset my option
So i changed the code lines like this :::
(defun InheritProp_er (s)
(if (/= s "function cancelled")
(if (= s "quit / exit abort")
(princ)
(princ (strcat "\nError:" s))
)
)
(setvar "cmdecho" cmd)
(setq *error* olderr)
(princ)
)
(defun c:InheritProp ()
(setq olderr *error*
*error* InheritProp_er
)
(setq sel (entsel "\nSelect object: "))
(if (null sel)
(progn
(princ (strcat "\n*Sorry no entity found*"))
(setq sel (entsel "\nTry again select object: "))
(if (null sel)
(progn
(princ
(strcat "\nFor the scond time no entity has been selectd: ")
)
(exit)
)
)
)
)
(setq cmd (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setq ent (car sel))
(setq edata (entget ent))
(setq etype (cdr (assoc 0 edata)))
(setq c (cdr (assoc 62 edata)))
(setq lt (cdr (assoc 6 edata)))
(setq l (cdr (assoc 8 edata)))
(setq lts (cdr (assoc 48 edata)))
(if (not lts)
(setq lts 1)
)
;;; ---------------- GENERAL
(princ (strcat "\n " etype))
(command "_color" "bylayer")
(command "_linetype" "s" "bylayer" "")
;;;
(command "_layer" "set" l "")
(setvar "celtscale" lts)
(if (eq etype "LINE")
(progn
(setq lts (cdr (assoc 48 edata))) ;
(command "_ltscale" lts)
)
)
;;; ---------------- ARC
(if (eq etype "ARC")
(progn (setq lts (cdr (assoc 48 edata)))
(command "_ltscale" lts)
)
)
;;; ---------------- CIRCLE
(if (eq etype "CIRCLE")
(progn (setq lts (cdr (assoc 48 edata)))
(command "_ltscale" lts)
)
)
;;; ---------------- ELLIPSE
(if (eq etype "ELLIPSE")
(progn (setq lts (cdr (assoc 48 edata)))
(command "_ltscale" lts)
)
)
;;; ---------------- SPLINE
(if (eq etype "SPLINE")
(progn (setq lts (cdr (assoc 48 edata)))
(command "_ltscale" lts)
)
)
;;; ---------------- HATCH
(if (eq etype "HATCH")
(progn
(setvar "HPNAME" (cdr (assoc 2 edata))) ;gets hatch pattern
(setvar "HPSCALE" (cdr (assoc 41 edata)));gets hatch scale
(setvar "HPANG" (cdr (assoc 52 edata)));gets hatch angle
)
)
;;; ---------------- LWPOLYLINE
(if (eq etype "LWPOLYLINE")
(progn
(setq lts (cdr (assoc 48 edata)))
(command "_ltscale" lts)
(setq W1 (cdr (assoc 40 edata)))
(setq W2 (cdr (assoc 41 edata)))
)
)
;;; ---------------- MLINE
(if (eq etype "MLINE")
(progn
)
)
(if (eq etype "LEADER")
(progn (setq st (cdr (assoc 3 edata)))
(command "_dimstyle" "r" st)
)
)
(if (eq etype "DIMENSION")
(progn
(setq dst (cdr (assoc 3 edata)))
(command "_dimstyle" "r" dst)
)
)
(if (eq etype "TEXT")
(princ)
(progn (setq c (cdr (assoc 62 edata)));COLOR
(setq l (cdr (assoc 8 edata)));LAYER
(setq s (cdr (assoc 7 edata)));STYLE
(setq f (cdr (assoc 4 edata)));FONT
(setq h (cdr (assoc 40 edata)));HEIGHT
(setq w (cdr (assoc 41 edata)));WIDTH
(setq a (angtos (cdr (assoc 50 edata)) 0 4));ROTATION ANGLE
(setq tx (cdr (assoc 1 edata)));text value
(setq in (cdr (assoc 10 edata)));insertion point
(setvar "cmdecho" 1)
(command "erase" sel "")
(command "_style" s "" h w "" "" "" "" "text" in a tx "dtext""")
)
)
(if (eq etype "MTEXT")
(princ)
(progn (setq c (cdr (assoc 62 edata)));COLOR
(setq l (cdr (assoc 8 edata)));LAYER
(setq s (cdr (assoc 7 edata)));STYLE
(setq f (cdr (assoc 4 edata)));FONT
(setq h (cdr (assoc 40 s)));HEIGHT
(setq w (cdr (assoc 41 edata)));WIDTH
(setq a (angtos (cdr (assoc 50 edata)) 0 4));ROTATION ANGLE
(setq in (cdr (assoc 10 edata)));insertion point
(setvar "cmdecho" 0);
(command "erase" sel "")
(command "_style" s "" "" "" "" "" "" "")
)
)
(setvar "cmdecho" 1)
(setq *error* oldererr)
(princ)
)
;end InheritProp.lsp
There are plenty of problems in what is written above.
Fo example ::
In "LWPOLYLINE" entity type section, W1 and W2 values do not change an autocad system variable. But if I start entering a polyline, after 1st point is set, I get a prompt Specify next point or [Arc/Halfwidth/Length/Undo/Width]: Let me enter “W” The default value now is 0.00 I change it to 5.00. The next time I start a new polyline the default valuw for “W” is 5.00. Thas says to me that there’s a System value holding my optional value (5.00). That means, needed more code :::
;;; ---------------- LWPOLYLINE
(if (eq etype "LWPOLYLINE")
(progn
(setq lts (cdr (assoc 48 edata)))
(command "_ltscale" lts)
(setq W1 (cdr (assoc 40 edata)))
(command "_????? " W1)
Or >>> (setvar "?????" W1)
(setq W2 (cdr (assoc 41 edata)))
(command "_????? " W2)
Or >>> (setvar "?????" W2) )
)
The same for other Property values for other entity types set but not assigned to system variables.
In addition, MLINE entity type is empty
Sorry, my lisp knowledge is poor.
I write plenty of codes in Pascal and I maintain my AutoCAD extension using the AutoCAD Application OLE object and this all is friendly to me. But working with OLE Object is much slower than lisp codes because lisp is embedded to the AutoCAD environment. Lisp has a much different syntax than pascal and is very difficult to me, to change anything written in lisp.
I think can do the proper changes, so the command will work as I describe.
Thanks,
Gery.