Lisp doesn't work anymore without changing lisp or settings AutoCad 2018

Lisp doesn't work anymore without changing lisp or settings AutoCad 2018

Sandervp
Advocate Advocate
1,141 Views
9 Replies
Message 1 of 10

Lisp doesn't work anymore without changing lisp or settings AutoCad 2018

Sandervp
Advocate
Advocate

Hello everybody,

 

I'm using a lisp file which (should) send all the xrefs to the back with draworder. But suddenly it doesn't work anymore.

I've reloaded him in the startup suite but this doesn't work.

 

It could be because the xref isn't a dwg but a pdf, but I don't know.

 

Nothing is changed. I didn't change something in the settings from AutoCad, no other lisp is added and there was no software update.

 

Does anyone know what the reason could be?

 

Thank you

 

Sander

 

Showed command lines after using the command:

"Command: XDR
_.draworder
Select objects: 0 found
Select objects:
Command: _b Unknown command "B". Press F1 for help."

 

; set all Xref's to back
[code]
(DEFUN c:xdr ( / curent curset newset)
(vl-load-com)
(SETQ newset (SSADD))
(IF (SETQ curset (SSGET "X" '((0 . "INSERT"))))
(WHILE (SETQ curent (SSNAME curset 0))
(SETQ curobj (VLAX-ENAME->VLA-OBJECT curent))
(IF (= T (VLAX-PROPERTY-AVAILABLE-P curobj 'path))
(SSADD curent newset)
)
(SSDEL curent curset)
)
) 
(command "_.draworder" newset "" "_b")
[/code]
  (princ)
)
0 Likes
Accepted solutions (1)
1,142 Views
9 Replies
Replies (9)
Message 2 of 10

dlanorh
Advisor
Advisor

@Sandervp wrote:

Hello everybody,

 

I'm using a lisp file which (should) send all the xrefs to the back with draworder. But suddenly it doesn't work anymore.

I've reloaded him in the startup suite but this doesn't work.

 

It could be because the xref isn't a dwg but a pdf, but I don't know.

 

Nothing is changed. I didn't change something in the settings from AutoCad, no other lisp is added and there was no software update.

 

Does anyone know what the reason could be?

 

Thank you

 

Sander

 

Showed command lines after using the command:

"Command: XDR
_.draworder
Select objects: 0 found
Select objects:
Command: _b Unknown command "B". Press F1 for help."

 

; set all Xref's to back
[code]
(DEFUN c:xdr ( / curent curset newset)
(vl-load-com)
(SETQ newset (SSADD))
(IF (SETQ curset (SSGET "X" '((0 . "INSERT"))));; (0 . "PDFUNDERLAY")
(WHILE (SETQ curent (SSNAME curset 0))
(SETQ curobj (VLAX-ENAME->VLA-OBJECT curent))
(IF (= T (VLAX-PROPERTY-AVAILABLE-P curobj 'path))
(SSADD curent newset)
)
(SSDEL curent curset)
)
) 
(command "_.draworder" newset "" "_b")
[/code]
  (princ)
)

A PDF Underlay is not a block. Try swapping out (0 . "INSERT") with the red code above

I am not one of the robots you're looking for

0 Likes
Message 3 of 10

CADaSchtroumpf
Advisor
Advisor
Accepted solution

Hi,

With little change for select and condition. Try this:

(DEFUN c:xdr ( / curent curset newset)
	(vl-load-com)
	(SETQ newset (SSADD))
	(IF (SETQ curset (SSGET "_X" '((0 . "INSERT,PDFUNDERLAY"))))
		(WHILE (SETQ curent (SSNAME curset 0))
			(SETQ curobj (VLAX-ENAME->VLA-OBJECT curent))
			(IF (OR (VLAX-PROPERTY-AVAILABLE-P curobj 'Path) (eq "AcDbPdfReference" (VLAX-GET-PROPERTY curobj 'ObjectName)))
				(SSADD curent newset)
			)
			(SSDEL curent curset)
		)
	)
	(command "_.draworder" newset "" "_b")
	(princ)
)
Message 4 of 10

ronjonp
Mentor
Mentor

You might just need to check that 'newset' exists before passing it to the draworder command:

(defun c:xdr (/ curent curset newset)
  (vl-load-com)
  (setq newset (ssadd))
  (if (setq curset (ssget "X" '((0 . "INSERT"))))
    (while (setq curent (ssname curset 0))
      (setq curobj (vlax-ename->vla-object curent))
      (if (= t (vlax-property-available-p curobj 'path))
	(ssadd curent newset)
      )
      (ssdel curent curset)
    )
  )
  (if newset (command "_.draworder" newset "" "_b"))
  (princ)
)
0 Likes
Message 5 of 10

john.uhden
Mentor
Mentor

Um, newset exists by virtue of

(setq newset (ssadd))

Bur it may be empty, so it would be better to

(if (> (sslength newset) 0) ...) 

John F. Uhden

0 Likes
Message 6 of 10

Sandervp
Advocate
Advocate

Thank you!

 

The lisp is working again.

But I still doesn't understand why it suddenly didn't work anymore.

0 Likes
Message 7 of 10

CADaSchtroumpf
Advisor
Advisor

@Sandervp  a écrit :

Thank you!

 

The lisp is working again.

But I still doesn't understand why it suddenly didn't work anymore.


You say:

It could be because the xref isn't a dwg but a pdf, but I don't know.

 

Yes it's the cause; you don't select PDFUNDERLAY in your code and the PDFUnderLay haven't the property 'Path

0 Likes
Message 8 of 10

CADaSchtroumpf
Advisor
Advisor

And if you want to make the code more reliable, the remark from john.uhden is relevant.

Replace

(command "_.draworder" newset "" "_b")

by

(if (not (zerop (sslength newset))) (command "_.draworder" newset "" "_b"))
0 Likes
Message 9 of 10

ronjonp
Mentor
Mentor

@john.uhden wrote:

Um, newset exists by virtue of

(setq newset (ssadd))

Bur it may be empty, so it would be better to

(if (> (sslength newset) 0) ...) 


Very true .. perhaps something like this 🙂

(defun c:xdr (/ a b)
  ;; RJP » 2020-01-13
  (vlax-for b (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
    (and (= -1 (vlax-get b 'isxref)) (setq a (cons (strcat (vla-get-name b) ",") a)))
  )
  (if (setq b (ssget "_X"
		     (list '(-4 . "<OR")
			   '(0 . "PDFUNDERLAY")
			   '(-4 . "<AND")
			   '(0 . "INSERT")
			   (cons 2 (apply 'strcat a))
			   '(-4 . "AND>")
			   '(-4 . "OR>")
		     )
	      )
      )
    (progn (setvar 'cmdecho 0) (command "_.draworder" b "" "_b") (setvar 'cmdecho 1))
    (print "No xrefs or PDF Underlays found in drawing!")
  )
  (princ)
)
(vl-load-com)

*Added PDF Underlay to filter

0 Likes
Message 10 of 10

john.uhden
Mentor
Mentor
That looks workable, but I am concerned about your yellow smiling face. I
suggest you see your doctor regarding jaundice. 😕

John F. Uhden

0 Likes