View Full Version : Change the style of aec objects via lisp
Mr Cory
2007-06-27, 05:33 AM
Does anyone know if its possible to write into a lisp code that changes the style of an aecobject?
Im trying to create a series of lisps that will create aecpolygon that have been set up the same as our standard hatches. Im trying to do this because im sick of needing to adjust a hatch in a drawing and it isnt asso to anything so i have to redo the hatch, where as if all the hatches were aecpolygons i can just change the grips. Thats the theory anyway lol
Any help in much appricated! (btw i have the rest of the lisp just need to know how to change the style)
jwanstaett
2007-06-28, 03:03 PM
;;John W. Anstaett 06/28/2007
;;Tested in ADT 2007 should work in other rev.
(vl-load-com)
;;this should be the first line in all program that use ActiveX
;;This function loads the extended AutoLISP functions
;;provided with Visual LISP. The Visual LISP extensions implement
;;ActiveX and AutoCAD reactor support through AutoLISP, and also
;;provide ActiveX utility and data conversion functions,
;;dictionary handling functions, and curve measurement functions.
;;Testme
;;comand function to test the Changestylename function
;;After loading the lisp
;;use the command testme
(defun c:Testme ()
(setq vbobj (vlax-ename->vla-object (car (entsel))))
;Get the VLA-object
(changestylename vbobj "test2") ;Call the Changestylename Function
;set "test2" to the name of the new style
;Style must me in the drawing or it error on you
)
;;Function changestylename
;; input
;;myobj A VLA-object.
;;newstylename the name of the the new style
;;Return Values Nil, if successful
;;Will error if stylename not in the drawing
;;Display a Alert if the Stylename can not be change
(defun changeStylename (myobj newstylename)
(if (vlax-property-available-p myobj "stylename" t)
(progn ;you can set the stylename on this object
(print (vlax-get-property myobj "stylename"))
;this line print the old stylename
;delete the above line if you do not need the old stylename printed
(vlax-put-property myobj "stylename" newstylename)
;this line set the new stylename
;Will error if the stylename is not in the drawing
)
(progn ;your Can Not set the stylename on this object
(alert "You Can Not Set The Styename On This Object")
;delete this line if you do not need the alert
)
)
)
Mr Cory
2007-06-28, 09:43 PM
Does that change the style of an object or change the name of the object?
jwanstaett
2007-06-28, 10:54 PM
Does that change the style of an object or change the name of the object?
It change the stylename of the object with change the style of the object to the new stylename
Mr Cory
2007-06-29, 12:54 AM
It change the stylename of the object with change the style of the object to the new stylename
So it wont change the current style of an object to an existing one?
jwanstaett
2007-06-29, 01:53 PM
it change the style to the new style but the new style must existing in the drawing. load and test the program and see how it work
So it wont change the current style of an object to an existing one?
Mr Cory
2007-06-30, 03:12 AM
Ok so which lines do i need to change to the style i want? I take it is where ever it says "stylename"?
Mr Cory
2007-07-01, 11:11 PM
I now get the alert "you can not change the style name on this object" :?
I tried this on a wall and a aecpolygon
jwanstaett
2007-07-02, 07:17 PM
it change the style to the new style but the new style must existing in the drawing. load and test the program and see how it workNo in the test fiction change the "test2" to the new style you need.
jwanstaett
2007-07-02, 07:53 PM
I now get the alert "you can not change the style name on this object" :?
I tried this on a wall and a aecpolygon(if (vlax-property-available-p myobj "stylename" t)
The "stylename" in the above line of code is the property that is being check for on the object that myobj point to. The changestylename Function need no change to work with all object that you can change the style of.
All you do is the change the way you call the function.
exp:
(changestylename x, "newxx")
where x is = to a VLA-object.
and "newxx" is the name of the new style
if you can not change the style on object x you get the alert "you can not change the style name on this object"
if the style newxx is not in the drawing you will get a error.
what you need to do how is to replace the testme function with a new one that call the chagestylename function the way you need it to.
Mr Cory
2007-07-02, 09:44 PM
;;John W. Anstaett 06/28/2007
;;Tested in ADT 2007 should work in other rev.
(vl-load-com)
;;this should be the first line in all program that use ActiveX
;;This function loads the extended AutoLISP functions
;;provided with Visual LISP. The Visual LISP extensions implement
;;ActiveX and AutoCAD reactor support through AutoLISP, and also
;;provide ActiveX utility and data conversion functions,
;;dictionary handling functions, and curve measurement functions.
;;Testme
;;comand function to test the Changestylename function
;;After loading the lisp
;;use the command testme
(defun c:Testme ()
(setq vbobj (vlax-ename->vla-object (car (entsel))))
;Get the VLA-object
(changestylename vbobj "KGR - Brick Veneer - 194 - New Entry") ;Call the Changestylename Function
;set "test2" to the name of the new style
;Style must me in the drawing or it error on you
)
;;Function changestylename
;; input
;;myobj A VLA-object.
;;newstylename the name of the the new style
;;Return Values Nil, if successful
;;Will error if stylename not in the drawing
;;Display a Alert if the Stylename can not be change
(defun changeStylename (myobj newstylename)
(if (vlax-property-available-p myobj "KGR - Brick Veneer - 194 - New Entry" t)
(progn ;you can set the stylename on this object
(print (vlax-get-property myobj "stylename"))
;this line print the old stylename
;delete the above line if you do not need the old stylename printed
(vlax-put-property myobj "stylename" newstylename)
;this line set the new stylename
;Will error if the stylename is not in the drawing
)
(progn ;your Can Not set the stylename on this object
(alert "You Can Not Set The Styename On This Object")
;delete this line if you do not need the alert
)
)
)
Is this not correct? Sorry to be a pain
jwanstaett
2007-07-02, 10:44 PM
;;John W. Anstaett 06/28/2007
;;Tested in ADT 2007 should work in other rev.
(vl-load-com)
;;this should be the first line in all program that use ActiveX
;;This function loads the extended AutoLISP functions
;;provided with Visual LISP. The Visual LISP extensions implement
;;ActiveX and AutoCAD reactor support through AutoLISP, and also
;;provide ActiveX utility and data conversion functions,
;;dictionary handling functions, and curve measurement functions.
;;Testme
;;comand function to test the Changestylename function
;;After loading the lisp
;;use the command testme
(defun c:Testme ()
(setq vbobj (vlax-ename->vla-object (car (entsel))))
;Get the VLA-object
(changestylename vbobj "KGR - Brick Veneer - 194 - New Entry") ;Call the Changestylename Function
;set "test2" to the name of the new style
;Style must me in the drawing or it error on you
)
;;Function changestylename
;; input
;;myobj A VLA-object.
;;newstylename the name of the the new style
;;Return Values Nil, if successful
;;Will error if stylename not in the drawing
;;Display a Alert if the Stylename can not be change
(defun changeStylename (myobj newstylename)
(if (vlax-property-available-p myobj "stylename" t)
(progn ;you can set the stylename on this object
(print (vlax-get-property myobj "stylename"))
;this line print the old stylename
;delete the above line if you do not need the old stylename printed
(vlax-put-property myobj "stylename" newstylename)
;this line set the new stylename
;Will error if the stylename is not in the drawing
)
(progn ;your Can Not set the stylename on this object
(alert "You Can Not Set The Styename On This Object")
;delete this line if you do not need the alert
)
)
)
Is this not correct? Sorry to be a pain
see the change in red
Mr Cory
2007-07-02, 10:50 PM
Cancell that!! Your a legend!!! Thank you! (and thanks for you patience) :) I may need some help adding in the rest of my lisp though
Mr Cory
2007-07-02, 10:56 PM
(defun c:bb ()
(command "osmode" "0")
(setq a (getpoint "\nPick internal Point:"))
(command "_.-boundary" a "" "aecpolygon" "c" "pl" "l" "" "y" "" "-OSNAP" "End,Mid,Cen,Node,Quad,Int,Perp,Ext")
(princ))
;;John W. Anstaett 06/28/2007
;;Tested in ADT 2007 should work in other rev.
(vl-load-com)
;;this should be the first line in all program that use ActiveX
;;This function loads the extended AutoLISP functions
;;provided with Visual LISP. The Visual LISP extensions implement
;;ActiveX and AutoCAD reactor support through AutoLISP, and also
;;provide ActiveX utility and data conversion functions,
;;dictionary handling functions, and curve measurement functions.
;;Testme
;;comand function to test the Changestylename function
;;After loading the lisp
;;use the command testme
(defun c:Testme ()
(setq vbobj (vlax-ename->vla-object (car (entsel))))
;Get the VLA-object
(changestylename vbobj "Hatches - Weatherboard") ;Call the Changestylename Function
;set "test2" to the name of the new style
;Style must me in the drawing or it error on you
)
;;Function changestylename
;; input
;;myobj A VLA-object.
;;newstylename the name of the the new style
;;Return Values Nil, if successful
;;Will error if stylename not in the drawing
;;Display a Alert if the Stylename can not be change
(defun changeStylename (myobj newstylename)
(if (vlax-property-available-p myobj "stylename" t)
(progn ;you can set the stylename on this object
(print (vlax-get-property myobj "stylename"))
;this line print the old stylename
;delete the above line if you do not need the old stylename printed
(vlax-put-property myobj "stylename" newstylename)
;this line set the new stylename
;Will error if the stylename is not in the drawing
)
(progn ;your Can Not set the stylename on this object
(alert "You Can Not Set The Styename On This Object")
;delete this line if you do not need the alert
)
)
)
Basically i want to be able to combine these to lisps now, Is that possible?
vBulletin® v3.6.7, Copyright ©2000-2010, Jelsoft Enterprises Ltd.