Jump to content
shailujp

Selecting Nested attribute text enity to remove hatch over it

Recommended Posts

shailujp

Hi all,

 

 

I need help on selecting a nested object which is attributed text from the block to be able to remove hatch over it. Below is the code that I'm using currently (not mine originaly, I tweaked it a bit for my application). This code just works for the whole block but doesnt allow me to select just the text.

 

 
(defun Fixhatch (/ Hatchfix objct)
(while
     (setq Hatchfix (entsel "\nSelect Hatch to fix (or Enter to close):"))
            (redraw (car Hatchfix) 3)
            (Alert "\n***Select object(s) to clear/skip hatch:***")
     (setq objct (ssget))
        
     (if (eq (cdr (assoc 0 (entget (setq Hatchfix (car Hatchfix))))) "HATCH")
    
     (command "_.-hatchedit" Hatchfix "Ad" "s" objct "" "")
  (princ "\nSelected entity is not a hatch.")
      );end if
);end while
     
);end defun

 

 

New Picture.jpg

 

As you can see the text TB6 is an attribute text of the rectangle block and I want to remove hatch just from the text.

 

Can this be done?

 

Thanks in advance.

Share this post


Link to post
Share on other sites
Tharwat
(defun c:Test (/ s)
 ;; Tharwat 21.10.2013    ;;
 (or Doc
     (setq Doc (vla-get-ActiveDocument (vlax-get-acad-object)))
 )
 (while
   (and (setq s (car (nentsel "\n Select Hatch in Block to delete :")))
        (eq (cdr (assoc 0 (entget s))) "HATCH")
   )
    (vl-catch-all-apply
      'vla-delete
      (list (vlax-ename->vla-object s))
    )
    (vla-regen Doc AcAllViewports)
 )
 (princ)
)
(vl-load-com)

Share this post


Link to post
Share on other sites
Lee Mac

As far as I know, even if the attribute subentity is supplied to the HATCHEDIT command (using an nentsel selection), the command will only process the primary block reference entity, hence creating the hatch boundary around the block.

Share this post


Link to post
Share on other sites
shailujp
(defun c:Test (/ s)
;; Tharwat 21.10.2013 ;;
(or Doc
(setq Doc (vla-get-ActiveDocument (vlax-get-acad-object)))
)
(while
(and (setq s (car (nentsel "\n Select Hatch in Block to delete :")))
(eq (cdr (assoc 0 (entget s))) "HATCH")
)
(vl-catch-all-apply
'vla-delete
(list (vlax-ename->vla-object s))
)
(vla-regen Doc AcAllViewports)
)
(princ)
)
(vl-load-com)

 

Hi Tharwat,

 

I tried using your code but it just deletes the hatch. This is not how I intended. May be I did not explain it well.

 

Below image shows my lisp does the "INCORRECT" version. If somehow I could get the "CORRECT" version so that the hatch skips the attribute text only (not the whole block).

New Picture (1).jpg

 

I see what Lee is saying using nentsel but limited to only select the upper level entity (which is block).

 

Is there a way around this?

Share this post


Link to post
Share on other sites
pBe

Is the hatch part of the block? or a separate entity?

Share this post


Link to post
Share on other sites
shailujp
Is the hatch part of the block? or a separate entity?

 

Hatch is a separate entity. And its added by a lisp utility which adds hatch to multiple clouding in one go.

Share this post


Link to post
Share on other sites
pBe

Here's how i would approach the problem:

 

Select the attribute entity

Copy selected nested entity

Create a TEXT matching the ATTRIBUTE properties

Run your FIXHATCH thingy

Remove associative property of hatch

Delete copied TEXT string

 

EDIT: YES in one go.

Share this post


Link to post
Share on other sites
shailujp
Here's how i would approach the problem:

 

Select the attribute entity

Copy selected nested entity

Create a TEXT matching the ATTRIBUTE properties

Run your FIXHATCH thingy

Remove associative property of hatch

Delete copied TEXT string

 

EDIT: YES in one go.

 

Thanks pBe for your suggestion.

 

But this is exactly what I have been doing as a work around so far. But then it requires more work to be done.

 

I was thinking AutoLISP may have a different method to tackle this. Also, the remove hatching is not just limited to text only. Sometimes, I have to select other-than-text entities as well from the block.

Share this post


Link to post
Share on other sites
pBe

But this is exactly what I have been doing as a work around so far. But then it requires more work to be done.

 

Well, not really shailujp, Hang on i'll write a short code for ATTRIBUTES...

 

EDIT:Modified for multiple selection and selected entity type

 

(defun c:HIH (/ _tempE hat ob a2t atb prop atb hat holes ); Hole in Hatch
(defun _tempE (ne / tmp)
 (setq tmp (entmakex (entget (car ne))))
 (vla-transformby
   (vlax-ename->vla-object tmp)
   (vlax-tmatrix (caddr ne))
 )
 tmp
)
;;;	Borrowed from LM	;;;
;;;   mod from /= to wcmatch  	;;;
(defun _selectobject ( msg obj fun / sel )
       (while
           (progn (setvar 'errno 0) (setq sel (car (setq itm ((eval fun) msg))))
               (cond
                   (   (= 7 (getvar 'errno))
                       (princ "\nMissed, try again.")
                   )
                   (   (= 'ename (type sel))
                       (if (not (wcmatch  (cdr (assoc 0 (entget sel))) obj))
                           (princ "\nInvalid object selected.")
                       )
                   )
               )
           )
       )
       itm
   )
;;;				;;;
(if  (setq holes (ssadd) hat (_selectobject "\nSelect Hatch: "     "HATCH"  'entsel))
 (progn
   [color="blue"](redraw (car hat) 3)[/color]
(while
  (Setq ob (_selectobject "\nSelect objects to exclude hatch: " "ATTRIB,*LINE,*TEXT,CIRCLE" 'nentselp))
  (ssadd 
  (if (eq (cdr (assoc 0 (entget (car ob)))) "ATTRIB")
		(progn
		  (setq a2t (vlax-ename->vla-object (car ob)))
		  (Setq	prop (mapcar '(lambda (p)
					(vlax-get a2t p)
				      )
				     '("Insertionpoint" "Textstring" "Height")))
		  (setq  atb	(vlax-invoke
			  (vlax-get (vla-get-ActiveLayout
				      (vla-get-activedocument (vlax-get-acad-object))
				    ) 'Block ) 'AddText
			  (cadr prop)
			  (car prop)
			  (caddr prop)
			)
		  )(vlax-vla-object->ename atb)
		)
    (_tempE ob)
    ) Holes)
 [color="blue"] (redraw (ssname holes (1- (sslength holes))) 3)[/color]
  )
(command "_.-hatchedit" (setq hat (Car hat)) "Ad" "s" holes "" "")
(vla-put-AssociativeHatch (vlax-ename->vla-object hat) :vlax-false)
   	(command "_.erase" holes "")
)
 )(princ)
 )

 

EDIT:Modified for multiple selection

Edited by pBe

Share this post


Link to post
Share on other sites
Lee Mac

Great idea pBe - thinking outside the box :thumbsup:

 

Here is my implementation of your idea, using functions from my Burst Upgraded program:

 

([color=BLUE]defun[/color] c:fixhatch ( [color=BLUE]/[/color] _selectobject att hat obj txt )

   ([color=BLUE]defun[/color] _selectobject ( msg obj fun [color=BLUE]/[/color] sel )
       ([color=BLUE]while[/color]
           ([color=BLUE]progn[/color] ([color=BLUE]setvar[/color] 'errno 0) ([color=BLUE]setq[/color] sel ([color=BLUE]car[/color] (([color=BLUE]eval[/color] fun) msg)))
               ([color=BLUE]cond[/color]
                   (   ([color=BLUE]=[/color] 7 ([color=BLUE]getvar[/color] 'errno))
                       ([color=BLUE]princ[/color] [color=MAROON]"\nMissed, try again."[/color])
                   )
                   (   ([color=BLUE]=[/color] 'ename ([color=BLUE]type[/color] sel))
                       ([color=BLUE]if[/color] ([color=BLUE]/=[/color] obj ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 ([color=BLUE]entget[/color] sel))))
                           ([color=BLUE]princ[/color] [color=MAROON]"\nInvalid object selected."[/color])
                       )
                   )
               )
           )
       )
       sel
   )

   ([color=BLUE]if[/color]
       ([color=BLUE]and[/color]
           ([color=BLUE]setq[/color] hat (_selectobject [color=MAROON]"\nSelect Hatch: "[/color]     [color=MAROON]"HATCH"[/color]  '[color=BLUE]entsel[/color]))
           ([color=BLUE]setq[/color] att (_selectobject [color=MAROON]"\nSelect Attribute: "[/color] [color=MAROON]"ATTRIB"[/color] '[color=BLUE]nentsel[/color]))
           ([color=BLUE]setq[/color] obj ([color=BLUE]vlax-ename->vla-object[/color] att))
       )
       ([color=BLUE]if[/color] ([color=BLUE]setq[/color] txt
               ([color=BLUE]if[/color] ([color=BLUE]and[/color] ([color=BLUE]vlax-property-available-p[/color] obj 'mtextattribute) ([color=BLUE]=[/color] [color=BLUE]:vlax-true[/color] ([color=BLUE]vla-get-mtextattribute[/color] obj)))
                   (iburst:matt2mtext ([color=BLUE]entget[/color] att))
                   (iburst:att2text   ([color=BLUE]entget[/color] att))
               )
           )
           ([color=BLUE]progn[/color]
               ([color=BLUE]command[/color] [color=MAROON]"_.-hatchedit"[/color] hat [color=MAROON]"_DI"[/color] [color=MAROON]"_.-hatchedit"[/color] hat [color=MAROON]"_AD"[/color] [color=MAROON]"_S"[/color] txt [color=MAROON]""[/color] [color=MAROON]""[/color])
               ([color=BLUE]entdel[/color] txt)
           )
           ([color=BLUE]princ[/color] [color=MAROON]"\nUnable to convert attribute to text."[/color])
       )
   )
   ([color=BLUE]princ[/color])
)

[color=GREEN];; The following functions are taken from Burst Upgraded:[/color]
[color=GREEN];; http://lee-mac.com/upgradedburst.html[/color]

([color=BLUE]defun[/color] iburst:removepairs ( itm lst )
   ([color=BLUE]vl-remove-if[/color] '([color=BLUE]lambda[/color] ( x ) ([color=BLUE]member[/color] ([color=BLUE]car[/color] x) itm)) lst)
)

([color=BLUE]defun[/color] iburst:remove1stpairs ( itm lst )
   ([color=BLUE]vl-remove-if[/color] '([color=BLUE]lambda[/color] ( x ) ([color=BLUE]if[/color] ([color=BLUE]member[/color] ([color=BLUE]car[/color] x) itm) ([color=BLUE]progn[/color] ([color=BLUE]setq[/color] itm ([color=BLUE]vl-remove[/color] ([color=BLUE]car[/color] x) itm)) [color=BLUE]t[/color]))) lst)
)
 
([color=BLUE]defun[/color] iburst:att2text ( enx )
   ([color=BLUE]entmakex[/color]
       ([color=BLUE]append[/color] '((0 . [color=MAROON]"TEXT"[/color]))
           (iburst:removepairs '(000 002 070 074 100 280)
               ([color=BLUE]subst[/color] ([color=BLUE]cons[/color] 73 ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 74 enx))) ([color=BLUE]assoc[/color] 74 enx) enx)
           )
       )
   )
)

([color=BLUE]defun[/color] iburst:matt2mtext ( enx )
   ([color=BLUE]entmakex[/color]
       ([color=BLUE]append[/color] '((0 . [color=MAROON]"MTEXT"[/color]) (100 . [color=MAROON]"AcDbEntity"[/color]) (100 . [color=MAROON]"AcDbMText"[/color]))
           (iburst:remove1stpairs  '(001 007 010 011 040 041 050 071 072 073 210)
               (iburst:removepairs '(000 002 042 043 051 070 074 100 101 102 280 330 360) enx)
           )
       )
   )
)

([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color])

Share this post


Link to post
Share on other sites
shailujp

I'm must commend both of you (Lee & pBe). Great stuff. Now, I have to find a way to incorporate it in my master lisp.

 

Just one more thing. What if I have a large area with multiple attributes to select to clear hatch?

 

Other than the attribute text, is it too much to ask if I have only text inside a block to be holed in hatch (not the attribute). Can this work for both?

(Sorry to alter the path but things started to click once I saw this happening).

Share this post


Link to post
Share on other sites
pBe
Great idea pBe - thinking outside the box :thumbsup:

Here is my implementation of your idea, using functions from my Burst Upgraded program:

 

Thanks Lee, you know me, i'm just the idea guy, I leave the elegant coding to you guys

 

I was thinking AutoLISP may have a different method to tackle this. Also, the remove hatching is not just limited to text only. Sometimes, I have to select other-than-text entities as well from the block.

 

I'm must commend both of you (Lee & pBe). Great stuff. Now,

Just one more thing. What if I have a large area with multiple attributes to select to clear hatch?

 

Other than the attribute text, is it too much to ask if I have only text inside a block to be holed in hatch (not the attribute). Can this work for both?

(Sorry to alter the path but things started to click once I saw this happening).

 

Thank you shailujp. Yes it can be done, Lets wait for LM to modify the code he posted, It's more complete than the one i wrote :D

I'm pretty sure its easy

Share this post


Link to post
Share on other sites
shailujp
Thanks Lee, you know me, i'm just the idea guy, I leave the elegant coding to you guys

 

 

 

 

 

Thank you shailujp. Yes it can be done, Lets wait for LM to modify the code he posted, It's more complete than the one i wrote :D

I'm pretty sure its easy

 

Thanks pBe. I'll be waiting for this eagerly.

Share this post


Link to post
Share on other sites
shailujp

Hi Lee,

 

Could you please help me on this?

Share this post


Link to post
Share on other sites
Bhull1985

Lee's superior coding has made him a busy man, but I would wager he will get back to this in due time. Sorry, he's just helped me with a completely separate issue on another forum. It's downright amazing, frankly, to keep all the codes separate but accurate regardless...

Share this post


Link to post
Share on other sites
pBe

Other than the attribute text, is it too much to ask if I have only text inside a block to be holed in hatch (not the attribute). Can this work for both?

(Sorry to alter the path but things started to click once I saw this happening).

 

Code modified to work on either TEXT or ATTRIBUTE, also for selected entity types [CIRCLE, LINE, LWPOLYLINE]

 

ps. Yes, also MULTIPLE selection

Share this post


Link to post
Share on other sites
shailujp
Code modified to work on either TEXT or ATTRIBUTE, also for selected entity types [CIRCLE, LINE, LWPOLYLINE]

 

ps. Yes, also MULTIPLE selection

 

Nice work pBe. Works perfectly fine for attribute texts. Just few minor hick-ups for other type of text. I have attached the .dwg file so that you can see what happens. Cyan color text are plain text outside of block. Top block is attribute block so no issues with that. Other remaining entities are text but inside a block (BANNER, LT OP, BN, NU WH etc.).

 

1) When I click on Cyan plain text (not inside block), it gives me error bad transformation matrix and terminates. Also it creates a copy of the text but since programm terminates, it leave the 2nd copy and doesnt get erased.

 

2) Text within blocks do not seem to be selected (although they are). This is display thing which make me doubt whether or not they are really selected. Can anything be done.

 

3) Did you also attempt to add other type of entities (circle, ellipse, arc, lines)? It seems that it also gives me bad transformation matrix error and creates a duplicate copy of it.

hatchfix2.dwg

Share this post


Link to post
Share on other sites
pBe
....Cyan color text are plain text outside of block.....

 

*** I wasn't counting on entities outside the block. but i have an idea how to distinguish the selected enity. i'll work on this later.

 

2) Text within blocks do not seem to be selected (although they are). This is display thing which make me doubt whether or not they are really selected. Can anything be done.

 

That item is easy. [refer to updated code]

 

3) Did you also attempt to add other type of entities (circle, ellipse, arc, lines)? It seems that it also gives me bad transformation matrix error and creates a duplicate copy of it.

 

Refer to ***

 

I'll get back to you later shailujp

Share this post


Link to post
Share on other sites
shailujp
*** I wasn't counting on entities outside the block. but i have an idea how to distinguish the selected enity. i'll work on this later.

 

 

 

 

That item is easy. [refer to updated code]

 

 

 

Refer to ***

 

I'll get back to you later shailujp

 

Hi pBe, I tried your updated code. It highlights hatch and then for attribute text since it creates a temporary duplicate text, it make me sure about a valid selection. The only issue is with the text which are in the block but not attributes. They dont seem to get highlighted since they dont create a ghost.

 

Did this work for you?

 

Clarification regarding other types of entities (lines/arc/circles etc...): I do not want to select other types of objects. This utility is needed only for text objects. For the other objects, my utility works fine and I do not want to combine two. I had to scratch my head a bit on how I want to use this but finally I'm clear.

 

And please take your time....I can definately wait.

Edited by shailujp

Share this post


Link to post
Share on other sites
shailujp

Hi pBe,

 

Have you had time to resolve last few hurdles on this routine?

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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