Jump to content

how to change hatch type within an XREF


AHMED18

Recommended Posts

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?

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

thanks,

it works,but changes are lost when the drawing is reopened

no way to find any thing to keep it in the dwg. :lol:

Link to comment
Share on other sites

thanks,

it works,but changes are lost when the drawing is reopened

no way to find any thing to keep it in the dwg. :lol:

 

 

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.

Link to comment
Share on other sites

thanks,

it works,but changes are lost when the drawing is reopened

no way to find any thing to keep it in the dwg. :lol:

 

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.

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