David Kozina
Usenet Archive
- Joined
- Sep 6, 2000
- Messages
- 310
- Reaction score
- 0
There were some comments made a few weeks ago regarding the utter lack of necesity for the *entire* set of vla- functions - and that that entire set could be reduced to 3 vlax- functions: vlax-invoke-method, vlax-get-property, and vlax-put-property.
So - after reviewing my code for vla- functions, I noticed that, with respects to the vla-put- property functions, once I replaced them with their vlax- equivalents, they looked like a prime target for further optimization...
IOW, once I changed this code:
(vla-put-Color _obj acByBlock)
(vla-put-Layer _obj "0")
(vla-put-Linetype _obj "BYBLOCK")
(vla-put-LineWeight _obj acLnWtByBlock)
to this:
(vlax-put-property _obj 'Color acByBlock)
(vlax-put-property _obj 'Layer "0")
(vlax-put-property _obj 'Linetype "BYBLOCK")
(vlax-put-property _obj 'LineWeight acLnWtByBlock)
it seemed that now it could be reduced further, with a small 'wrapper' function, PutProperties, which goes like so:
; applies new property values to an object
(defun PutProperties
(_obj ; object to apply new property values to Property_alst ; assoc list of new ('Property . Value) dotted pairs / ; ) ; begin ; ...process property pairs (mapcar (function (lambda (Property_dp) (vlax-put-property _obj (car Property_dp) (cdr Property_dp) ) );_end lambda );_end function ; begin list Property_alst ; end list );_end mapcar ; end );_end defun
However, if I try to work with an actual list of dotted pairs:
(PutProperties
_obj
'(('Color . acByBlock)
('Layer . "0")
('Linetype . "BYBLOCK")
('Lineweight . acLnWtByBlock)
)
)
AutoCAD revolts under the strain. Why?
(I've tried various combinations of a literal quoted association list, to no avail.) I imagine it's a pretty basic oversight on my part- but I can't see it. Can a quoted list be used here?
Yet, using list and cons does work:
(PutProperties
_obj
(list
(cons 'Color acByBlock)
(cons 'Layer "0")
(cons 'Linetype "BYBLOCK")
(cons 'Lineweight acLnWtByBlock)
)
)
It just isn't as compact as I was hoping for.
Finally, is this basically a good/sound idea or not?
Have you found a more effective/efficient way to use vlax-put-property in your code? Would error-trapping be a good thing to add to the PutProperties routine, or would it just bog it down needlessly?
Comments would be appreciated.
Best regards,
David Kozina
So - after reviewing my code for vla- functions, I noticed that, with respects to the vla-put- property functions, once I replaced them with their vlax- equivalents, they looked like a prime target for further optimization...
IOW, once I changed this code:
(vla-put-Color _obj acByBlock)
(vla-put-Layer _obj "0")
(vla-put-Linetype _obj "BYBLOCK")
(vla-put-LineWeight _obj acLnWtByBlock)
to this:
(vlax-put-property _obj 'Color acByBlock)
(vlax-put-property _obj 'Layer "0")
(vlax-put-property _obj 'Linetype "BYBLOCK")
(vlax-put-property _obj 'LineWeight acLnWtByBlock)
it seemed that now it could be reduced further, with a small 'wrapper' function, PutProperties, which goes like so:
; applies new property values to an object
(defun PutProperties
(_obj ; object to apply new property values to Property_alst ; assoc list of new ('Property . Value) dotted pairs / ; ) ; begin ; ...process property pairs (mapcar (function (lambda (Property_dp) (vlax-put-property _obj (car Property_dp) (cdr Property_dp) ) );_end lambda );_end function ; begin list Property_alst ; end list );_end mapcar ; end );_end defun
However, if I try to work with an actual list of dotted pairs:
(PutProperties
_obj
'(('Color . acByBlock)
('Layer . "0")
('Linetype . "BYBLOCK")
('Lineweight . acLnWtByBlock)
)
)
AutoCAD revolts under the strain. Why?
(I've tried various combinations of a literal quoted association list, to no avail.) I imagine it's a pretty basic oversight on my part- but I can't see it. Can a quoted list be used here?
Yet, using list and cons does work:
(PutProperties
_obj
(list
(cons 'Color acByBlock)
(cons 'Layer "0")
(cons 'Linetype "BYBLOCK")
(cons 'Lineweight acLnWtByBlock)
)
)
It just isn't as compact as I was hoping for.
Finally, is this basically a good/sound idea or not?
Have you found a more effective/efficient way to use vlax-put-property in your code? Would error-trapping be a good thing to add to the PutProperties routine, or would it just bog it down needlessly?
Comments would be appreciated.
Best regards,
David Kozina