Change LINETYPE of block(s) with attributes

Change LINETYPE of block(s) with attributes

Anonymous
Not applicable
1,286 Views
4 Replies
Message 1 of 5

Change LINETYPE of block(s) with attributes

Anonymous
Not applicable

I've been messing with this for a while now and I can't get it to work

Below is the routine I came up with to change the linetype of a block(s) with attributes to HIDDEN

but it's obviously not working, so if someone can where my error id=s I'd really appreciate it

 

(DEFUN C:CHGTAG(/ A1 F TNAM CNTR)
(SETVAR "CMDECHO" 0)
(vl-load-com)


(SETQ A1(SSGET))
(SETQ CNTR 0)


(REPEAT(SSLENGTH A1)


(SETQ ENAME(SSNAME A1 CNTR))
(SETQ F(ENTGET ENAME))
(SETQ TNAM(CDR(ASSOC 0 F)))
(SETQ TNAM2(CDR(ASSOC 2 F)))
(SETQ LYR(CDR(ASSOC 8 F)))
(SETQ INSPT(CDR(ASSOC 10 F)))
(SETQ LEN1(STRLEN TNAM2))
(SETQ LEN2(- LEN1 4))
(SETQ BNUM(SUBSTR TNAM2 5 LEN2))
(SETQ BNAME(STRCAT "_Tag."BNUM))

 

(IF(AND(= TNAM "INSERT")(=(SUBSTR TNAM2 1 4)"_Tag"))
(PROGN

 

(WHILE(AND(NOT FOUNDIT)
(SETQ ENT1(ENTNEXT ENAME))
(=(CDR(ASSOC 0 (ENTGET ENT1)))"ATTRIB")
); end and
(SETQ ATT(vlax-ename->vla-object ENT1))
(IF(=(vla-get-TagString ATT)"HOLD")
(SETQ ATTH(vla-get-TextString ATT))
); end if
(SETQ ENT2(ENTNEXT ENT1))
(SETQ ATT2(vlax-ename->vla-object ENT2))
(IF(=(vla-get-TagString ATT2)"NOTE")
(SETQ ATTN(vla-get-TextString ATT2))
); end if
); end while

 

(SETQ G1(ENTLAST))
(COMMAND "EXPLODE" ENAME)
(SETQ GP1 NIL)
(SETQ GP1(GROUP G1))

(COMMAND ".CHANGE" GP1 "" "P" "S" "0.75" "LT" "Hidden" "")
(COMMAND ".BLOCK" BNAME INSPT GP1 "")
(COMMAND ".PURGE" "B" TNAM2 "N")
(COMMAND ".LAYER" "S" LYR "")
(COMMAND ".INSERT" BNAME INSPT "" "" "" ATTH ATTN)

 

); end progn
); end if

(COMMAND "LAYER" "S" OLDLAY "")
(SETQ CNTR(1+ CNTR))
(SETVAR "OSMODE" OLDMODE)

); end repeat
(PRINC))

 

Thanks,

Larry

0 Likes
Accepted solutions (1)
1,287 Views
4 Replies
Replies (4)
Message 2 of 5

Kent1Cooper
Consultant
Consultant

Describe what doesn't work about it.  Does it fail to load?  Does it load but the command name isn't recognized?  Does it take the command name but not do something you expect it to, or do something you don't expect it to?  Are there error messages?  Etc., etc.

 

We can't test it without some Blocks with your particular form of Attribute tag names, and it looks like the quantity of Attributes may be critical, too.  Can you post a sample drawing that has some?

 

The FOUNDIT variable is something I've used, so some of that code may come from me, but I use it when looking for a particular Attribute, and as a trigger to not look any further once it finds that one.  That doesn't appear to be wanted, and you're not setting it to any non-nil value anywhere, so your (while) loop would be endless without those checks on finding a next entity and its being an Attribute.  I think you could just remove the (NOT FOUNDIT) element from that (AND) function.

 

In case the problem should be related to this, you don't include the code for your (GROUP) function, but from the way it's used, I don't think you need it.  When you Explode things, the results end up as the Previous selection.  And you may as well go straight for properties with the CHPROP command, rather than the CHANGE command with its subsidiary Properties option.  I think you could replace this much:

 

(SETQ GP1 NIL)
(SETQ GP1(GROUP G1))

(COMMAND ".CHANGE" GP1 "" "P" "S" "0.75" "LT" "Hidden" "")

 

with this:

 

(COMMAND ".CHPROP" "_previous" "" "S" "0.75" "LT" "Hidden" "")

 

Also, as I recall, an Attribute tag turns into all UPPER-case even if you give it lower-case content in making the AttDef.  Your comparison that looks for "_Tag" in an (=) function will fail if it's really "_TAG".

Kent Cooper, AIA
0 Likes
Message 3 of 5

Anonymous
Not applicable

I do believe the (while(and(not foundit) section is from a routine you helped me with a while back to list attributes values from a block,

so I tried inserting that into a routine I've been using to change the linetype of blocks that don't have attributes, to retrieve the two attribute values needed to be able to recreate the block

I can't send the block with attributes because the block is created using LISP, so I've attached a drawing with some of the blocks in it

The problem I'm having is that the command works on every other block selected

What's happening is the group GP1 isn't being created the first time you select a block, or the third time or the fifth time, etc

The first block selected is exploded but not recreated into a block, the second block selected changes to hidden and gets recreated into a block

But even though the linetype changes the linetype scale is 1.0 instead of 0.75

I tried removing the (NOT FOUNDIT) but still had the same problem

Use the routine below, the one I originally posted had an issue and didn't work at all

 

(DEFUN C:CHGTAG(/ A1 F TNAM CNTR)
(SETVAR "CMDECHO" 0)
(SETQ OLDLAY(GETVAR "CLAYER"))
(vl-load-com)

(SETQ A1(SSGET))

(SETQ CNTR 0)

(REPEAT(SSLENGTH A1)

(SETQ ENAM(SSNAME A1 CNTR))
(SETQ F(ENTGET ENAM))
(SETQ TNAM(CDR(ASSOC 0 F)))
(SETQ TNAM2(CDR(ASSOC 2 F)))
(SETQ LYR(CDR(ASSOC 8 F)))
(SETQ INSPT(CDR(ASSOC 10 F)))
(SETQ LEN1(STRLEN TNAM2))
(SETQ LEN2(- LEN1 4))
(SETQ BNUM(SUBSTR TNAM2 5 LEN2))
(SETQ BNAME(STRCAT "_Tag."BNUM))

(setq ent(ssname a1 0))
(while
(and
(not foundit)
(setq ent(entnext ent))
(=(cdr(assoc 0 (entget ent)))"ATTRIB")
); end and
(setq att(vlax-ename->vla-object ent))
(if(=(vla-get-TagString att)"HOLD")
(setq atth(vla-get-TextString att))
); end if
(setq ent(entnext ent))
(setq att2(vlax-ename->vla-object ent))
(if(=(vla-get-TagString att2)"NOTE")
(setq attn(vla-get-TextString att2))
); end if
); end while

(IF(AND(= TNAM "INSERT")(=(SUBSTR TNAM2 1 4)"_Tag"))
(PROGN

(SETQ G1(ENTLAST))
(COMMAND "EXPLODE" ENAM)
(SETQ GP1 NIL)
(SETQ GP1(GROUP G1))

(IF(= GP1 NIL)
(SETQ GP1(GROUP G1))
); end if

(COMMAND ".CHPROP" GP1 "" "S" "0.75" "LT" "Hidden" "")
(COMMAND ".BLOCK" BNAME INSPT GP1 "")

(COMMAND "LAYER" "S" LYR "")
(COMMAND "INSERT" BNAME INSPT "" "" "0" ATTH ATTN)
); end progn
); end if

(COMMAND "LAYER" "S" OLDLAY "")

(SETQ CNTR(1+ CNTR))
); end repeat

(PRINC))

0 Likes
Message 4 of 5

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

....

The problem I'm having is that the command works on every other block selected

What's happening is the group GP1 isn't being created the first time you select a block, or the third time or the fifth time, etc

....


Hard to diagnose without seeing the code for the (GROUP) function.  But I still don't think you need it.  Have you tried just giving the results-of-Explode Previous selection to the CHPROP command, and forgetting the G1 and GP1 variables and the (GROUP) function altogether?

 

By the way, a slightly shorter way of determining whether a Block name starts with _Tag, instead of this:

 

(= (SUBSTR TNAM2 1 4) "_Tag")

 

would be this:

 

(wcmatch TNAM2 "_Tag*")

Kent Cooper, AIA
0 Likes
Message 5 of 5

Anonymous
Not applicable

OK. Now I have it working

Even though it was in the routine I last posted I had tried removing the G1 and GP1 variables and the (GROUP) function but it still didn't work

because I had didn't remove the GP1 from the block creation  (COMMAND ".BLOCK" BNAME INSPT GP1 "")

All I had to do was replace it with  "_previous"

So that section looks like this now:

(COMMAND "EXPLODE" ENAM)
(COMMAND ".CHPROP" "_previous" "" "S" "0.75" "LT" "Hidden" "")
(COMMAND ".BLOCK" BNAME INSPT "_previous" "")

 

Thanks again for all your help Kent

 

Larry

0 Likes