Error AutoCAD.Application Not applicable

Error AutoCAD.Application Not applicable

Anonymous
Not applicable
2,394 Views
16 Replies
Message 1 of 17

Error AutoCAD.Application Not applicable

Anonymous
Not applicable
Hi, I'm getting this error message while execute (vlax-invoke ob1 'intersectwith ob2 mod) and unable to predict the error. Could you please support on this ;program to segregate the objects (defun intersectionsbetweensets ( ss1 ss2 / id1 id2 ob1 ob2 rtn ) (VL-LOAD-COM) (vl-list-loaded-vlx) (setq id1 nil id2 nil ob1 nil ob2 nil rtn nil ) (repeat (setq id1 (sslength ss1)) (setq ob1 (vlax-ename->vla-object (ssname ss1 (setq id1 (1- id1)))) );repeat (repeat (setq id2 (sslength ss2)) (setq ob2 (vlax-ename->vla-object (ssname ss2 (setq id2 (1- id2)))) rtn (cons (intersections ob1 ob2 acextendnone) rtn))) );repeat (apply 'append (reverse rtn)) );defun ;program to find intersection between two selectionsets (defun C:x_intersets_horizontal (/ ss1 ss2 ) (vl-load-com) (vl-list-loaded-vlx) (setq ss1 nil ss2 nil ss nil ent1 nil ssno nil pnt nil) (if (and (setq ss1 (ssget "l")) (setq ss2 (ssget "X")) );and (progn ; and true condition (setq ent1 (ssname ss1 0) ss (ssdel ent1 ss2)) (if (= ss nil) (progn ; (= ss nil) true condition (setq pnt nil) (command "setvar" "users1" "0") );progn (= ss nil) true condition (progn ; (= ss nil) false condition (setq ssno (sslength ss)) (setq pnt (intersectionsbetweensets ss1 ss)) ;find the intersection (if (= pnt nil) (progn ; (= pnt nil) true condition (setq ss1 nil ss nil) (command "setvar" "users1" "0") );progn (= pnt nil) (progn ; false condition (setq no 0 no (length pnt)) (setq ss1 nil ss nil) (command "setvar" "users1" no) );progn (= pnt nil) false condition );if (= pnt nil) );progn (= ss nil) false condition ); if (= ss nil) ); progn and true condition ); if );defun ;program to find the intersection of objects (defun intersections ( ob1 ob2 mod / lst rtn ) (vl-load-com) (vl-list-loaded-vlx) (setq lst nil lst (vlax-invoke ob1 'intersectwith ob2 mod) );setq (repeat (/ (length lst) 3) (setq rtn (cons (list (car lst) (cadr lst) (caddr lst)) rtn) lst (cdddr lst) );setq );repeat (reverse rtn) );defun
0 Likes
2,395 Views
16 Replies
Replies (16)
Message 2 of 17

Alexander.Rivilis
Mentor
Mentor

1. Please use button Code for posting formated code on forum:

2016-10-06_23-33-11.png

2. Not all kind of entities has IntersectWith method, which can find intersection. For example, for 3DSOLIDs it is not applicable method.

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 3 of 17

Anonymous
Not applicable
Hi thanks for the reply. The most of the entities are 2D only (Text, Mtext, line, polyline, blocks). It execting some time and mostly through this error Thanks, vallimanalan.t
0 Likes
Message 4 of 17

Alexander.Rivilis
Mentor
Mentor

Text and Mtext and Block also can not been intersection. You can check intersection of BoundingBox of this type of entities.

For Polyline's and Line's (and for other type of Curve, such as ARC, CIRCLE, ELLIPSE, SPLINE and so on) you can check intersections with IntersectWith method.

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 5 of 17

Anonymous
Not applicable
Hi, Could you please give some guidelines on "bounding box" intersection in lisp Thanks, vallimanalan.T
0 Likes
Message 6 of 17

Alexander.Rivilis
Mentor
Mentor

In VisualLisp/AutoLisp there are no methods to check intersection of BoundingBox, but you can create BoundingBox as polyline and check intersection with polyline and other entity. Example of getting BoundigBox: http://www.lee-mac.com/boundingbox.html

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 7 of 17

Anonymous
Not applicable
Hi, Thank you. I will check it and come back to you. vallimanalan.T
0 Likes
Message 8 of 17

Anonymous
Not applicable
Hi, Greetings. As advised, I have tried the intersect method in vlisp but am unable to get 100% output. I would like to share the code with you.But am unable to attach in the forum and also I unable to find Rich text - tool box contents for button code. Could you please support on this. Thanks, vallimanalan.T
0 Likes
Message 9 of 17

Alexander.Rivilis
Mentor
Mentor

@Anonymous wrote:
.... I would like to share the code with you.But am unable to attach in the forum and also I unable to find Rich text - tool box contents for button code. Could you please support on this...

I can not support with this problem. You have to write about this problem to Community Feedback forum.

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 10 of 17

Ranjit_Singh
Advisor
Advisor

Can you post a sample drawing and explain what the routine is doing? I am trying to generate same error but I cannot without the right drawing.

0 Likes
Message 11 of 17

Anonymous
Not applicable

Hi,

 

Thanks. Please find the code and sample output for your kind information. Please correct me where I did mistake.thanks.

;program reset the user variable

(defun c:reset_value()  

(command "setvar" "users1" "0")

(command "setvar" "users2" "0")


);defun

  



;------------------------------------------------------------------------------------------------------


;program to find intersection between two selectionsets

(defun c:x_intersets (/ ss1 ss2 )

	  (vl-load-com)

	  (vl-list-loaded-vlx)

	  (defun *error* ( msg )
	    
	        (princ "error: ")
	        (princ msg)
	        (princ)
	  )

	  (setq ss1 nil ss2 nil ss nil 	ent1 nil ssno nil pnt nil)

  	  (setq X_value nil Y_value nil X1_value nil Y1_value nil)

	  (setq X_value (getreal "X_value:"))
	  (setq Y_value (getreal "Y_value:"))
	  (setq X1_value (getreal "X_value:"))
	  (setq Y1_value (getreal "Y_value:"))

  (if (and (setq ss1 (ssget "l"))

	 (setq ss2 (ssget "_C" (LIST X_value Y_value) (LIST X1_value Y1_value)))

	   );and

	 (progn ; and true condition

	      	      (setq  ent1 (ssname ss1 0) ss   (ssdel ent1 ss2)  )

		 (if (= ss nil)

			(progn
			  
				(setq ss ss2)

				(setq ssno (sslength ss2))

			);progn

			(progn

				  (setq ssno 0)

				  (setq ssno (sslength ss))

			 );progn
			
		);if

	      (if (= ssno 0) 

			(progn ; (= ssno 0) true condition

			  (command "setvar" "users1" "0")

			);progn (= ssno 0) true condition

			(progn ; (= ssno 0) false condition

				  (setq ssno (sslength ss))

				  (setq pnt (intersectionsbetweensets ss1 ss)) ;find the intersection

				  (if (=  pnt nil)

					    (progn ; (=  pnt nil)   true condition

						      (setq  ss1  nil  ss nil)

						      (command "setvar" "users1" "0")

					    );progn (=  pnt nil)

					    (progn ; false condition

						      (setq  no  0  no   (length pnt))

						      (setq  ss1  nil  ss nil)

						      (command "setvar" "users1" no)

					    );progn (=  pnt nil) false condition
				    
				    );if (=  pnt nil)
			  
			  );progn (= ssno 0) false condition
		
		); if (= ssno 0)
	      
	 ); progn and true condition

    ); if
  
  );defun

;------------------------------------------------------------------------------------------------------

;program to find the intersection of objects

(defun intersections ( ob1 ob2 mod / lst rtn )

	  (vl-load-com)

	  (vl-list-loaded-vlx)
	  
	  (setq lst nil

		lst (vlax-invoke ob1 'intersectwith ob2 mod)

		);setq

	  (repeat (/ (length lst) 3)

	    (setq rtn (cons (list (car lst) (cadr lst) (caddr lst)) rtn)

		  lst (cdddr lst)

		  );setq

	    );repeat

	  (reverse rtn)

 );defun

;------------------------------------------------------------------------------------------------------


;program to segregate the objects

(defun intersectionsbetweensets ( ss1 ss2 / id1 id2 ob1 ob2 rtn )

	  (VL-LOAD-COM)

	  (vl-list-loaded-vlx)

	  (setq id1 nil id2 nil ob1 nil ob2 nil rtn nil plst nil corner_pt nil op_corner_pt nil nent nil ob2 nil)

	  (setq ob1 (vlax-ename->vla-object ss1))

	  (repeat (setq id2 (sslength ss2))

	      	    (setq  ent2 (ssname ss2 (setq id2 (1- id2)))

		      	   obj  (vlax-ename->vla-object ent2)

			   plst nil corner_pt nil op_corner_pt nil nent nil ob2 nil

			   a nil b nil)



			(if
				   (and

					  (vlax-method-applicable-p obj 'getboundingbox)

					  (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-getboundingbox (list obj 'a 'b))))

					  (setq plst (mapcar 'vlax-safearray->list (list a b)))
				    )

			      (progn

					(if (/= plst nil)

						    (progn
						  
						  	(setq corner_pt 	(car plst)

							      op_corner_pt 	(cadr plst));setq

						  	(command "rectangle" corner_pt op_corner_pt "")

						  	(setq nent (entlast)

							      ob2  (vlax-ename->vla-object nent))


						     );progn

						    (progn

							(setq ob2 nil)
						    
						    );progn

					 );if
					

			       	);progn

			      	(setq ob2 nil)
			      
			   );if

		    	   (if (/= ob2 nil)

				(progn

				  	(setq  rtn (cons (intersections ob1 ob2 acextendnone) rtn))

			     		;(entdel nent)

				 );progn

			     	(progn

				  (setq rtn rtn)

				  )

			   );if
	    
	  );repeat

  (apply 'append (reverse rtn))

 );defun


;------------------------------------------------------------------------------------------------------

0 Likes
Message 12 of 17

Ranjit_Singh
Advisor
Advisor

I tried your code and it fails at the following statement.

 

(setq ob1 (vlax-ename->vla-object ss1))

You cannot use ename->vla-object on a selection set. Use a for statement or some other loop to get each entity and pass it's ename. You posted a pdf which does no good. I have no idea what kind of selection sets the function needs. Post a dwg file and provide some explanation on what selection sets to pass to the function.

 

0 Likes
Message 13 of 17

Anonymous
Not applicable

Hi,

 

Please ignore the previous code. Find the corrected one. Our intention to place text in dwg without overlapping on nearest objects. So we find the intersecting of text area (we creating rectangle based on text-character count) with nearest area.

 

what selection sets to pass to the function - Crossing method based object selection

 

;program reset the user variable

(defun c:reset_value()  

(command "setvar" "users1" "0")

(command "setvar" "users2" "0")


);defun

  



;------------------------------------------------------------------------------------------------------


;program to find intersection between two selectionsets

(defun c:x_intersets (/ ss1 ss2 )

	  (vl-load-com)

	  (vl-list-loaded-vlx)

	  (defun *error* ( msg )
	    
	        (princ "error: ")
	        (princ msg)
	        (princ)
	  )

	  (setq ss1 nil ss2 nil ss nil 	ent1 nil ssno nil pnt nil)

  	  (setq X_value nil Y_value nil X1_value nil Y1_value nil)

	  (setq X_value (getreal "X_value:"))
	  (setq Y_value (getreal "Y_value:"))
	  (setq X1_value (getreal "X_value:"))
	  (setq Y1_value (getreal "Y_value:"))

  (if (and (setq ss1 (ssget "l"))

	 (setq ss2 (ssget "_C" (LIST X_value Y_value) (LIST X1_value Y1_value)))

	   );and

	 (progn ; and true condition

	      	      (setq  ent1 (ssname ss1 0) ss   (ssdel ent1 ss2)  )

		 (if (= ss nil)

			(progn
			  
				(setq ss ss2)

				(setq ssno (sslength ss2))

			);progn

			(progn

				  (setq ssno 0)

				  (setq ssno (sslength ss))

			 );progn
			
		);if

	      (if (= ssno 0) 

			(progn ; (= ssno 0) true condition

			  (command "setvar" "users1" "0")

			);progn (= ssno 0) true condition

			(progn ; (= ssno 0) false condition

				  (setq ssno (sslength ss))

				  (setq pnt (intersectionsbetweensets ent1 ss)) ;find the intersection

				  (if (=  pnt nil)

					    (progn ; (=  pnt nil)   true condition

						      (setq  ss1  nil  ss nil)

						      (command "setvar" "users1" "0")

					    );progn (=  pnt nil)

					    (progn ; false condition

						      (setq  no  0  no   (length pnt))

						      (setq  ss1  nil  ss nil)

						      (command "setvar" "users1" no)

					    );progn (=  pnt nil) false condition
				    
				    );if (=  pnt nil)
			  
			  );progn (= ssno 0) false condition
		
		); if (= ssno 0)
	      
	 ); progn and true condition

    ); if
  
  );defun

;------------------------------------------------------------------------------------------------------

;program to find the intersection of objects

(defun intersections ( ob1 ob2 mod / lst rtn )

	  (vl-load-com)

	  (vl-list-loaded-vlx)
	  
	  (setq lst nil

		lst (vlax-invoke ob1 'intersectwith ob2 mod)

		);setq

	  (repeat (/ (length lst) 3)

	    (setq rtn (cons (list (car lst) (cadr lst) (caddr lst)) rtn)

		  lst (cdddr lst)

		  );setq

	    );repeat

	  (reverse rtn)

 );defun

;------------------------------------------------------------------------------------------------------


;program to segregate the objects

(defun intersectionsbetweensets ( ss1 ss2 / id1 id2 ob1 ob2 rtn )

	  (VL-LOAD-COM)

	  (vl-list-loaded-vlx)

	  (setq id1 nil id2 nil ob1 nil ob2 nil rtn nil plst nil corner_pt nil op_corner_pt nil nent nil ob2 nil)

	  (setq ob1 (vlax-ename->vla-object ss1))

	  (repeat (setq id2 (sslength ss2))

	      	    (setq  ent2 (ssname ss2 (setq id2 (1- id2)))

		      	   obj  (vlax-ename->vla-object ent2)

			   plst nil corner_pt nil op_corner_pt nil nent nil ob2 nil

			   a nil b nil)



			(if
				   (and

					  (vlax-method-applicable-p obj 'getboundingbox)

					  (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-getboundingbox (list obj 'a 'b))))

					  (setq plst (mapcar 'vlax-safearray->list (list a b)))
				    )

			      (progn

					(if (/= plst nil)

						    (progn
						  
						  	(setq corner_pt 	(car plst)

							      op_corner_pt 	(cadr plst));setq

						  	(command "rectangle" corner_pt op_corner_pt "")

						  	(setq nent (entlast)

							      ob2  (vlax-ename->vla-object nent))


						     );progn

						    (progn

							(setq ob2 nil)
						    
						    );progn

					 );if
					

			       	);progn

			      	(setq ob2 nil)
			      
			   );if

		    	   (if (/= ob2 nil)

				(progn

				  	(setq  rtn (cons (intersections ob1 ob2 acextendnone) rtn))

			     		;(entdel nent)

				 );progn

			     	(progn

				  (setq rtn rtn)

				  )

			   );if
	    
	  );repeat

  (apply 'append (reverse rtn))

 );defun


;------------------------------------------------------------------------------------------------------

0 Likes
Message 14 of 17

Ranjit_Singh
Advisor
Advisor

Hi Vallimanalan, one advise - it's a good idea to use spoiler tag when posting big codes.

Back to your code, I still do not see any issues. It works at my end. I would only advise to use (getpoint) to retrieve the X and Y values of the box. See formatted code below. This is exactly same as your code except for using command-s instead of command and some formatting. I have also attached a screencast showing how it runs at my end. Is this the expected end result? or am I still missing something? 

Formatted code

Spoiler
 
     ;program reset the user variable

(defun c:reset_value () (command "setvar" "users1" "0") (command "setvar" "users2" "0")) ;defun

     ;------------------------------------------------------------------------------------------------------

     ;program to find intersection between two selectionsets

(defun c:x_intersets  (/ ss1 ss2)
 (vl-load-com)
 (vl-list-loaded-vlx)
 (defun *error* (msg) (princ "error: ") (princ msg) (princ))
 (setq ss1  nil
       ss2  nil
       ss   nil
       ent1 nil
       ssno nil
       pnt  nil)
 (setq X_value nil
       Y_value nil
       X1_value nil
       Y1_value nil)
 (setq X_value (getreal "X_value:"))
 (setq Y_value (getreal "Y_value:"))
 (setq X1_value (getreal "X_value:"))
 (setq Y1_value (getreal "Y_value:"))
 (if (and (setq ss1 (ssget "l")) (setq ss2 (ssget "_C" (LIST X_value Y_value) (LIST X1_value Y1_value)))) ;and
  (progn ; and true condition
   (setq ent1 (ssname ss1 0)
         ss   (ssdel ent1 ss2))
   (if (= ss nil)
    (progn (setq ss ss2) (setq ssno (sslength ss2))) ;progn
    (progn (setq ssno 0) (setq ssno (sslength ss))) ;progn
    ) ;if
   (if (= ssno 0)
    (progn ; (= ssno 0) true condition
     (command "setvar" "users1" "0")) ;progn (= ssno 0) true condition
    (progn ; (= ssno 0) false condition
     (setq ssno (sslength ss))
     (setq pnt (intersectionsbetweensets ent1 ss)) ;find the intersection
     (if (= pnt nil)
      (progn ; (=  pnt nil)   true condition
       (setq ss1 nil
             ss  nil)
       (command "setvar" "users1" "0")) ;progn (=  pnt nil)
      (progn ; false condition
       (setq no 0
             no (length pnt))
       (setq ss1 nil
             ss  nil)
       (command "setvar" "users1" no)) ;progn (=  pnt nil) false condition
      ) ;if (=  pnt nil)
     ) ;progn (= ssno 0) false condition
    ) ; if (= ssno 0)
   ) ; progn and true condition
  )  ; if
 )   ;defun

     ;------------------------------------------------------------------------------------------------------

     ;program to find the intersection of objects

(defun intersections  (ob1 ob2 mod / lst rtn)
 (vl-load-com)
 (vl-list-loaded-vlx)
 (setq lst nil
       lst (vlax-invoke ob1 'intersectwith ob2 mod)) ;setq
 (repeat (/ (length lst) 3)
  (setq rtn (cons (list (car lst) (cadr lst) (caddr lst)) rtn)
        lst (cdddr lst)) ;setq
  )  ;repeat
 (reverse rtn)) ;defun

     ;------------------------------------------------------------------------------------------------------


     ;program to segregate the objects

(defun intersectionsbetweensets  (ss1 ss2 / id1 id2 ob1 ob2 rtn)
 (VL-LOAD-COM)
 (vl-list-loaded-vlx)
 (setq id1 nil
       id2 nil
       ob1 nil
       ob2 nil
       rtn nil
       plst nil
       corner_pt nil
       op_corner_pt nil
       nent nil
       ob2 nil)
 (setq ob1 (vlax-ename->vla-object ss1))
 (repeat (setq id2 (sslength ss2))
  (setq ent2         (ssname ss2 (setq id2 (1- id2)))
        obj          (vlax-ename->vla-object ent2)
        plst         nil
        corner_pt    nil
        op_corner_pt nil
        nent         nil
        ob2          nil
        a            nil
        b            nil)
  (if (and (vlax-method-applicable-p obj 'getboundingbox)
           (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-getboundingbox (list obj 'a 'b))))
           (setq plst (mapcar 'vlax-safearray->list (list a b))))
   (progn (if (/= plst nil)
           (progn (setq corner_pt    (car plst)
                        op_corner_pt (cadr plst)) ;setq
                  (command-s "_rectangle" corner_pt op_corner_pt)
                  (setq nent (entlast)
                        ob2  (vlax-ename->vla-object nent))) ;progn
           (progn (setq ob2 nil)) ;progn
           ) ;if
          ) ;progn
   (setq ob2 nil)) ;if
  (if (/= ob2 nil)
   (progn (setq rtn (cons (intersections ob1 ob2 acextendnone) rtn)) ;(entdel nent)
          ) ;progn
   (progn (setq rtn rtn))) ;if
  )  ;repeat
 (apply 'append (reverse rtn))) ;defun


     ;------------------------------------------------------------------------------------------------------

 Screecast

Spoiler

 

 

Message 15 of 17

Anonymous
Not applicable
Hi, thank you so much.. I will check and come back to you.thanks
0 Likes
Message 16 of 17

Anonymous
Not applicable

Hi,

 

Its working fine while run separately in AutoCAD.But while execute with project package, it not give 100% perfect output (i.e intersection points).so the text objects are overlapping with other objects.

 

FYI..Please..

 

Project description : We driving the AutoCAD objects properties and Auto lisp function from Excel VBA (reference the AutoCAD Library in Excel)  and Excel as a database.

 

AutoCAD version : AutoCAD 2013 SP2

 

I have the following questions

 

1.Is it any interface problem (ActiveX) with Excel and AutoCAD & Autolisp (I have included the reference list)

2.Is it any multi thread issues, because of that its skipping from the particular place.

 

Could you please advise me. thanks

 

 

0 Likes
Message 17 of 17

Ranjit_Singh
Advisor
Advisor

Sorry. VBA is out of my skillset . Hopefully someone else can help you out.

0 Likes