Jump to content

Recommended Posts

Posted

How can we determine in lisp if an xref is in model space or paper space?

Anybody has a code that detaches all xref in model space but retain the xref that are in paper space?

 

 

 

Posted

You could try this oldie

 

(defun c:detachx ( / *error* c_doc c_blks b_str ss cnt obj)

  (defun *error* ( msg )
    (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nAn Error : " msg " occurred.")))
    (princ)
  );_end_*error*_defun

  (setq c_doc (vla-get-activedocument (vlax-get-acad-object))
        c_blks (vla-get-blocks c_doc)
  );end_setq

  (vlax-for blk c_blks
    (if (= :vlax-true (vlax-get-property blk 'isxref)) (setq b_str (strcat b_str "," vlax-get-property blk 'name)))
  );end_for

  (setq b_str (vl-string-trim "," b_str)
        ss (ssget "_X" (list '(0 . "INSERT") '(410 . "Model") (cons 2 b_str)))
  );end_setq

  (cond (ss
          (repeat (setq cnt (sslength ss))
            (setq obj (vlax-ename->vla-object (ssname ss (setq cnt (1- cnt)))))
            (vla-detach obj)
          );end_repeat
        )
  );end_cond

  (princ)
);end_defun

 

There are no checks for locked layers, so ensure all relevant layers are unlocked. I would also test it on a copy of a drawing first. 

  • Like 1
Posted
7 hours ago, CAD_Noob said:

How can we determine in lisp if an xref is in model space or paper space?

Anybody has a code that detaches all xref in model space but retain the xref that are in paper space?

 

 

 

What if the same xref resides in model and paperspace?

Posted
11 hours ago, ronjonp said:

What if the same xref resides in model and paperspace?

 I don't have such case. Xref in Paperspace is commonly Titleblocks and legends only.

Posted
On 3/10/2020 at 3:29 PM, dlanorh said:

You could try this oldie

 


(defun c:detachx ( / *error* c_doc c_blks b_str ss cnt obj)

  (defun *error* ( msg )
    (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nAn Error : " msg " occurred.")))
    (princ)
  );_end_*error*_defun

  (setq c_doc (vla-get-activedocument (vlax-get-acad-object))
        c_blks (vla-get-blocks c_doc)
  );end_setq

  (vlax-for blk c_blks
    (if (= :vlax-true (vlax-get-property blk 'isxref)) (setq b_str (strcat b_str "," vlax-get-property blk 'name)))
  );end_for

  (setq b_str (vl-string-trim "," b_str)
        ss (ssget "_X" (list '(0 . "INSERT") '(410 . "Model") (cons 2 b_str)))
  );end_setq

  (cond (ss
          (repeat (setq cnt (sslength ss))
            (setq obj (vlax-ename->vla-object (ssname ss (setq cnt (1- cnt)))))
            (vla-detach obj)
          );end_repeat
        )
  );end_cond

  (princ)
);end_defun

 

There are no checks for locked layers, so ensure all relevant layers are unlocked. I would also test it on a copy of a drawing first. 

 

i got this error : 

 

Quote

Command: DETACHX
An Error : bad argument type: stringp nil occurred.
Command:

 

Posted

b_str needs a check like so:

(if (and (setq b_str (vl-string-trim "," b_str))
	   (setq ss (ssget "_X" (list '(0 . "INSERT") '(410 . "Model") (cons 2 b_str))))
      )					;end_setq
    (repeat (setq cnt (sslength ss))
      (setq obj (vlax-ename->vla-object (ssname ss (setq cnt (1- cnt)))))
      (vla-detach obj)
    )					;end_repeat
  )

 

Posted
8 hours ago, ronjonp said:

b_str needs a check like so:


(if (and (setq b_str (vl-string-trim "," b_str))
	   (setq ss (ssget "_X" (list '(0 . "INSERT") '(410 . "Model") (cons 2 b_str))))
      )					;end_setq
    (repeat (setq cnt (sslength ss))
      (setq obj (vlax-ename->vla-object (ssname ss (setq cnt (1- cnt)))))
      (vla-detach obj)
    )					;end_repeat
  )

 

(defun c:detachx ( / *error* c_doc c_blks b_str ss cnt obj)

  (defun *error* ( msg )
    (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nAn Error : " msg " occurred.")))
    (princ)
  );_end_*error*_defun

  (setq c_doc (vla-get-activedocument (vlax-get-acad-object))
        c_blks (vla-get-blocks c_doc)
  );end_setq

  (vlax-for blk c_blks
    (if (= :vlax-true (vlax-get-property blk 'isxref)) (setq b_str (strcat b_str "," vlax-get-property blk 'name)))
  );end_for

  (if (and (setq b_str (vl-string-trim "," b_str))
       (setq ss (ssget "_X" (list '(0 . "INSERT") '(410 . "Model") (cons 2 b_str))))
      )                    ;end_setq
    (repeat (setq cnt (sslength ss))
      (setq obj (vlax-ename->vla-object (ssname ss (setq cnt (1- cnt)))))
      (vla-detach obj)
    )                    ;end_repeat
  )
  (cond (ss
          (repeat (setq cnt (sslength ss))
            (setq obj (vlax-ename->vla-object (ssname ss (setq cnt (1- cnt)))))
            (vla-detach obj)
          );end_repeat
        )
  );end_cond

  (princ)
);end_defun

 

I incorporated this with @dlanorh lisp and i got this error

 

Quote

Command: DETACHX
An Error : bad argument type: stringp nil occurred.
Command:

 

Posted (edited)

This too:

(vlax-for blk c_blks
  (if (= :vlax-true (vlax-get-property blk 'isxref))
    (setq b_str (strcat (if b_str b_str "") "," vlax-get-property blk 'name))
  )
)					;end_for

@dlanorh can take care of any other issues that arise 😉

Edited by ronjonp
Posted
15 hours ago, CAD_Noob said:

(defun c:detachx ( / *error* c_doc c_blks b_str ss cnt obj)

  (defun *error* ( msg )
    (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nAn Error : " msg " occurred.")))
    (princ)
  );_end_*error*_defun

  (setq c_doc (vla-get-activedocument (vlax-get-acad-object))
        c_blks (vla-get-blocks c_doc)
  );end_setq

  (vlax-for blk c_blks
    (if (= :vlax-true (vlax-get-property blk 'isxref)) (setq b_str (strcat b_str "," vlax-get-property blk 'name)))
  );end_for

  (if (and (setq b_str (vl-string-trim "," b_str))
       (setq ss (ssget "_X" (list '(0 . "INSERT") '(410 . "Model") (cons 2 b_str))))
      )                    ;end_setq
    (repeat (setq cnt (sslength ss))
      (setq obj (vlax-ename->vla-object (ssname ss (setq cnt (1- cnt)))))
      (vla-detach obj)
    )                    ;end_repeat
  )
  (cond (ss
          (repeat (setq cnt (sslength ss))
            (setq obj (vlax-ename->vla-object (ssname ss (setq cnt (1- cnt)))))
            (vla-detach obj)
          );end_repeat
        )
  );end_cond

  (princ)
);end_defun

 

I incorporated this with @dlanorh lisp and i got this error

 

 

 

Sorry, lots of problems on my work computer, my antivirus is being overenthusiastic, and intermittantly thinks the mouse driver is malware. Trying to cut and paste code is a problem right now so I've attached an updated lisp that addresses the problems.

 

 

detachx.lsp

Posted
On 3/14/2020 at 2:12 AM, dlanorh said:

 

Sorry, lots of problems on my work computer, my antivirus is being overenthusiastic, and intermittantly thinks the mouse driver is malware. Trying to cut and paste code is a problem right now so I've attached an updated lisp that addresses the problems.

 

 

detachx.lsp 1.06 kB · 1 download

 

i still get the same error :(

Posted

OK, I've altered this slightly and tested (as previously). Are you sure these are xref dwgs and not underlays of some kind? To run type detx

 

 

detachx.lsp

  • Thanks 1
Posted
4 hours ago, dlanorh said:

OK, I've altered this slightly and tested (as previously). Are you sure these are xref dwgs and not underlays of some kind? To run type detx

 

 

detachx.lsp 1.04 kB · 0 downloads

 

It worked! Thank you so much for your time @dlanorh

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...