Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Automation Error. Calling method Clear of interface IAcadSelectionSet failed

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
aqdam1978
1691 Views, 3 Replies

Automation Error. Calling method Clear of interface IAcadSelectionSet failed

Hi,

 

I wrote a lisp program and I can't debug it!

 

this is a part of my code that cause to "; error: Automation Error. Calling method Clear of interface IAcadSelectionSet failed":

 

(foreach dwg files
(setq str "")
(command "undo" "BE")
(command "-insert" (strcat "\"*" path dwg "\"") '(10000 10000) 1 0)
(if (/= dwgN nil)(setq Col3(Append Col3 (list(GetAttrVal blk dwgN)))))
(if (/= t1 nil)(setq str(GetAttrVal blk t1)))
(if (/= t2 nil)(setq str(strcat str " - "(GetAttrVal blk t2))))
(if (/= t3 nil)(setq str(strcat str " - "(GetAttrVal blk t3))))
(if (/= t4 nil)(setq str(strcat str " - "(GetAttrVal blk t4))))
(setq Col4(Append Col4 (list str)))
(command "undo" "E" "undo" "B" "Y" "purge" "A" "*" "N") 
);;foreach

 and this is GetAttrVal:

 

(defun GetAttrVal (blkname att_tag / Val)
(if (and(/= blkname nil) (/= att_tag nil))
(progn  
  (vl-load-com)
  (ssget "x" (list '(0 . "INSERT") (cons 2 (strcat blkname ",`*U*")) '(66 . 1)))
  (vlax-for item (vla-get-activeselectionset
		   (vla-get-activedocument (vlax-get-acad-object))
		 )
    (if (eq (strcase blkname) (strcase (vla-get-effectivename item)))
		(foreach att (vlax-safearray->list (vlax-variant-value (vla-getattributes item)))
		  (if (= (strcase att_tag) (vla-get-tagstring att))	(setq Val (vla-get-textstring att)))
		);;foreach
    );;if
  )
);;progn
);;if/=
(if (= Val nil)(setq Val ""))
Val
)

 Please help me, I will go crazy! because of this error!

 

Thanks

 

 

3 REPLIES 3
Message 2 of 4
pbejse
in reply to: aqdam1978

 

(defun GetAttrVal (blkname att_tag / Val ss)
  (if (and (/= blkname nil) (/= att_tag nil) (ssget "x" (list '(0 . "INSERT") (cons 2 (strcat blkname ",`*U*")) '(66 . 1))))
    (progn (vl-load-com)
             (vlax-for item (setq ss (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
             (if (eq (strcase blkname) (strcase (vla-get-effectivename item)))
               (foreach att (vlax-safearray->list (vlax-variant-value (vla-getattributes item)))
                 (if (= (strcase att_tag) (vla-get-tagstring att))
                   (setq Val (vla-get-textstring att))
                 )
               )
               ;;foreach
             )
             ;;if
           )
           (vla-delete ss)
    )
    ;;progn
  )
  ;;if/=
  (if (= Val nil)
    (setq Val "")
  )
  Val
)

Always remember to delete the SelectionSet object when finished

 

Message 3 of 4
aqdam1978
in reply to: pbejse

Hi Pbejse,

 

Thanks for your help.

 

I have a question:

 

I founded this paragraph in autocad help:

 

Selection sets consume AutoCAD temporary file slots, so AutoLISP is not permitted to have more than 128 open at one time. If this limit is reached, AutoCAD cannot create any more selection sets and returns nil to all ssget calls. To close an unnecessary selection set variable, set it to nil.

 

and you used "vla-delete", what is differences between meaning of this paragraph and your "vla-delete" solution.

 

Thanks,

 

Abbas

 

 

Message 4 of 4
pbejse
in reply to: aqdam1978


@aqdam1978 wrote:

 I have a question:

 

I founded this paragraph in autocad help:

 

Selection sets consume AutoCAD temporary file slots, so AutoLISP is not permitted to have more than 128 open at one time. If this limit is reached, AutoCAD cannot create any more selection sets and returns nil to all ssget calls. To close an unnecessary selection set variable, set it to nil.

 

and you used "vla-delete", what is differences between meaning of this paragraph and your "vla-delete" solution.

 


As stated on your post , there are limits in selection set collection. so its either you clear ALL selections sets via at the start of the routine. (set it to nil)

 

(vlax-for sel
	(vla-get-selectionsets (vla-get-activedocument (vlax-get-acad-object)))
  		(vla-delete sel))

Not to be confused for vla-clear/vla-erase as the selection set will still exist. 

 

Or delete the selection set created during run time, in our case variable ss. 

 

(vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)))

and will be named as "CURRENT" then use  (vla-delete ss) <- wherein ss is a SelectionSet object  (also set it to nil)

 

The code you posted uses SSGET "_X" (pickset)  selection mode [combined with a  filter-list takes less lines of code]. THEN converts it to a SelectionSet object wherein you need to delete when finished.

 

You can however use the method below to itereate thru all objects on the active document.  Which doesnt require creation of a named SelectionSet , hence no need delete 

 

(vlax-for layout (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
  (vlax-for i (vla-get-block layout) (do your thing here [filter and what not]))
)

 

I would normally use the method above if i find the routine has a potential use to process multiple drawings via ObjectDBX. where ssget is not allowed.

 

Hope this helps

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost