Jump to content

XREF in MODEL SPACE


CAD_Noob

Recommended Posts

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?

 

 

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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:

 

Link to comment
Share on other sites

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
  )

 

Link to comment
Share on other sites

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:

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 :(

Link to comment
Share on other sites

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...