AHMED18 Posted July 16, 2018 Share Posted July 16, 2018 hi everyone! can someone help me with a lisp, select a hatch that is within an XREF and be able to change its type without entering the reference? Quote Link to comment Share on other sites More sharing options...
ronjonp Posted July 16, 2018 Share Posted July 16, 2018 Give this a try. (defun c:foo (/ _odbx a e e2 h o p pat) ;; Change your predefined pattern name here ;; Not much error checking... (setq pat "SOLID") (defun _odbx (/ doc v) (setq doc (vlax-get-acad-object)) (if (< (setq v (substr (getvar 'acadver) 1 2)) "16") (vla-getinterfaceobject doc "ObjectDBX.AxDbDocument") (vla-getinterfaceobject doc (strcat "ObjectDBX.AxDbDocument." v)) ) ) (cond ((and (setq e (nentsel "\nPick nested hatch: ")) (= 4 (length e)) (= "HATCH" (cdr (assoc 0 (entget (car e))))) (setq h (cdr (assoc 5 (entget (car e))))) (setq p (setq e2 (tblobjname "block" (cdr (assoc 2 (entget (car (last e)))))))) (setq p (cdr (assoc 1 (entget p)))) (setq p (findfile p)) (setq o (_odbx)) ) (cond ((vl-catch-all-error-p (vl-catch-all-apply 'vla-open (list o p))) (princ "\n*Error opening file...") ) ((setq a (vla-handletoobject o h)) (vl-catch-all-apply 'vla-setpattern (list a achatchpatterntypepredefined pat)) (vla-saveas o p) (vlax-release-object o) (command "-xref" "Reload" (cdr (assoc 2 (entget e2))) "") ) ) ) ) (princ) ) (vl-load-com) Quote Link to comment Share on other sites More sharing options...
AHMED18 Posted July 17, 2018 Author Share Posted July 17, 2018 give this a try. (defun c:foo (/ _odbx a e e2 h o p pat) ;; change your predefined pattern name here ;; not much error checking... (setq pat "solid") (defun _odbx (/ doc v) (setq doc (vlax-get-acad-object)) (if (< (setq v (substr (getvar 'acadver) 1 2)) "16") (vla-getinterfaceobject doc "objectdbx.axdbdocument") (vla-getinterfaceobject doc (strcat "objectdbx.axdbdocument." v)) ) ) (cond ((and (setq e (nentsel "\npick nested hatch: ")) (= 4 (length e)) (= "hatch" (cdr (assoc 0 (entget (car e))))) (setq h (cdr (assoc 5 (entget (car e))))) (setq p (setq e2 (tblobjname "block" (cdr (assoc 2 (entget (car (last e)))))))) (setq p (cdr (assoc 1 (entget p)))) (setq p (findfile p)) (setq o (_odbx)) ) (cond ((vl-catch-all-error-p (vl-catch-all-apply 'vla-open (list o p))) (princ "\n*error opening file...") ) ((setq a (vla-handletoobject o h)) (vl-catch-all-apply 'vla-setpattern (list a achatchpatterntypepredefined pat)) (vla-saveas o p) (vlax-release-object o) (command "-xref" "reload" (cdr (assoc 2 (entget e2))) "") ) ) ) ) (princ) ) (vl-load-com) thanks, but i want to change the type just in my drawing without any change in the reference xref Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 17, 2018 Share Posted July 17, 2018 thanks, but i want to change the type just in my drawing without any change in the reference xref Not possible. Quote Link to comment Share on other sites More sharing options...
ronjonp Posted July 17, 2018 Share Posted July 17, 2018 Not possible. Just tested this and it works .. but changes are lost when the drawing is reopened so not sure where the OP is going with this... (defun c:foo (/ e p) ;; Change your predefined pattern name here ;; Not much error checking... (setq p "EARTH") (cond ((and (setq e (car (nentsel "\nPick hatch: "))) (= "HATCH" (cdr (assoc 0 (entget e))))) (setq e (vlax-ename->vla-object e)) (vl-catch-all-apply 'vla-setpattern (list e achatchpatterntypepredefined p)) (vl-catch-all-apply 'vla-put-patternscale (list e (getvar 'dimscale))) (command "_regen") ) ) (princ) ) (vl-load-com) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 17, 2018 Share Posted July 17, 2018 Just tested this and it works .. but changes are lost when the drawing is reopened so not sure where the OP is going with this... (defun c:foo (/ e p) ;; Change your predefined pattern name here ;; Not much error checking... (setq p "EARTH") (cond ((and (setq e (car (nentsel "\nPick hatch: "))) (= "HATCH" (cdr (assoc 0 (entget e))))) (setq e (vlax-ename->vla-object e)) (vl-catch-all-apply 'vla-setpattern (list e achatchpatterntypepredefined p)) (vl-catch-all-apply 'vla-put-patternscale (list e (getvar 'dimscale))) (command "_regen") ) ) (princ) ) (vl-load-com) But any changes to the xref block definition will be reverted as soon as the xref is reloaded... Quote Link to comment Share on other sites More sharing options...
ronjonp Posted July 17, 2018 Share Posted July 17, 2018 Yup .. that's why I said I'm not sure where the OP is going with this .. maybe it's just a visual thing for the current session? Quote Link to comment Share on other sites More sharing options...
AHMED18 Posted July 18, 2018 Author Share Posted July 18, 2018 thanks, it works,but changes are lost when the drawing is reopened no way to find any thing to keep it in the dwg. Quote Link to comment Share on other sites More sharing options...
rlx Posted July 18, 2018 Share Posted July 18, 2018 thanks, it works,but changes are lost when the drawing is reopened no way to find any thing to keep it in the dwg. you're probably thinking about 'visretain' to be able to save the different xref layer status on a dwg basis. Of course you can bind the xref but then the whole xref idea can be flushed down the drain. Only other option would be to have 2 different layers for the hatch in the xref itself. Haven't done much with annotative blocks & hatches but don't think that work in xrefs. Quote Link to comment Share on other sites More sharing options...
ronjonp Posted July 18, 2018 Share Posted July 18, 2018 thanks, it works,but changes are lost when the drawing is reopened no way to find any thing to keep it in the dwg. Like Lee said you're asking for something that is not possible. The simplest way to achieve what you want is to have a block in the drawing not an xref .. or use the first code I posted and accept that the changes are saved to the xref. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.