I am trying to figure out how to covert my traditional selection set to a selection set that vla-wblock would use.
Here is my code:
(if (setq Sset (ssget "_X" (list '(0 . "INSERT")(cons 8 "LayerName")))) (progn (vla-wblock "c:\\temp\\testblock" Sset );_end wblock );_end progn );_end if
My questions are these:
1. Do i need to add ".dwg" on the end of the location?
2. How do I covert this selection set to the object that autocad needs to use?
3. Will this vla-wblock overright the block with that same name or do i need to delete the drawing with the same same that is already there first?
Solved! Go to Solution.
Solved by hmsilva. Go to Solution.
Redraiderr2009 wrote:
... My questions are these:
1. Do i need to add ".dwg" on the end of the location?
2. How do I covert this selection set to the object that autocad needs to use?
3. Will this vla-wblock overright the block with that same name or do i need to delete the drawing with the same same that is already there first?
1. no
2.
(if (setq Sset (ssget "_X" (list '(0 . "INSERT")(cons 8 "LayerName")))) (progn (setq Sset (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)))) (vla-wblock (vla-get-activedocument (vlax-get-acad-object)) "c:\\temp\\testblock" Sset ) );; progn );; if
3. yes it overwrites
hope that helps
Henrique
Most places I look at tell me to do it the way that you have posted, but I still get this error message when selecting the blocks. When I run the routine there are items in the selection set, but because it's a selection set in a variable it may not be the active selection set.
Make a selection of plants:
Select objects: Specify opposite corner: 23 found, 5 groups
Select objects:
Error: Automation Error. Calling method AddItems of interface IAcadSelectionSet
failed
Command: 'VLIDE
Yeah it worked outside the routine. There must have be some conflict with my selection sets. I ended up blanking all the selection sets out before it made this new selection and that did the trick. It was a likttle confusion as to why the last selection set made would not have been the activeselection set. I am willing to live with it.
@hmsilva wrote:
(if (setq Sset (ssget "_X" (list '(0 . "INSERT")(cons 8 "LayerName")))) (progn (setq Sset (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)))) ........
You need to delete Sset collection. after processing the selection , (vla-delete Sset) ActiveX is crazy that way.
or prior to selection you can ensure there are no "activeselectionset" by "clearing" the collection
(setq aDoc (vla-get-activedocument (vlax-get-acad-object))) (vlax-for i (vla-get-selectionsets aDoc) (vla-delete i)) (if (ssget "_X" '((0 . "TEXT"))) (vlax-for i (setq Selset (vla-get-ActiveSelectionSet adoc)) .....)
or somethingt to that effect. you get the idea 🙂
HTH
To avoid that better yet to use named selection set
I'm personally prefer to use PickFirstSelectionSet
something like this:
(defun C:VWB (/ acapp adoc fcode fdata pfs) (setq adoc (vla-get-activedocument (setq acapp (vlax-get-acad-object))) pfs (vla-get-pickfirstselectionset adoc) ) (vla-zoomextents acapp) (vl-catch-all-apply 'vla-clear (list pfs)) (setq fcode (vlax-safearray-fill (vlax-make-safearray vlax-vbinteger '(0 . 2)) (list 0 8 410) ) fdata (vlax-safearray-fill (vlax-make-safearray vlax-vbvariant '(0 . 2)) (list "text" "ANNO-TEXT" (getvar "ctab"))) ) (vla-select pfs acselectionsetall nil nil fcode fdata) (if (> (vla-get-count pfs) 0) (vla-wblock adoc "c:\\test\\wblock_text" pfs )); hard coded, change to suit (vla-zoomprevious acapp) (princ) )