Jump to content

Recommended Posts

Posted (edited)

Hello everyone ,

 

Hope that someone would tell me how to get only Blocks that are included of Attributes .

 

(ssget "_:L" '((0 . ................

Many thanks dear buddies. :)

 

Michaels

Edited by Michaels
  • Replies 25
  • Created
  • Last Reply

Top Posters In This Topic

  • Michaels

    10

  • Lee Mac

    8

  • pBe

    4

  • BlackBox

    3

Top Posters In This Topic

Posted (edited)

'((0 . "INSERT")(2 . "BLOCK_Name")(66 . 1)))

 

or

 

 
(ssget (list (cons 2 bnm)'(66 . 1)) )

 

bnm is the block name (a variable)

where 66

Variable attributes-follows flag

series of attributes entities is expected to follow the insert, terminated by seqend entity

:)

 

 

and of course there's also constant attributes that doesnt have the DXF code 66.

 

otherewise use VL

 


(defun c:Get_value (/ blks cnt rslt enxt value_list)
  (setq 
      blks (ssget "_X" '((2 . "Block_name"))) cnt 0 rslt 0)
(while (< cnt (sslength blks))
   (setq enxt  (vlax-ename->vla-object (ssname blks cnt)))
    (cond ((eq (vla-get-Hasattributes enxt) :vlax-true)
   (setq value_list (mapcar 'vla-get-textstring
      (vlax-safearray->list (variant-value 
           (vla-getconstantattributes enxt)))
    )
   )
  )
 )(print value_list)
  (setq cnt (1+ cnt))
)
 (princ)
 )

 

Hope this helps

Edited by pBe
Fat fingers syndrome
Posted

Thank you ,

 

So how to get the all the Attributes (tagtexts) of that block one by one , as a matter of a column like (print "\n" tagtext)

 

Appreciated.

Posted

I am sorry, it doesn't work - and here is the error message .

 

So can't we make it with DXF codes ?

 

; error: ActiveX Server returned an error: Invalid index

 

Thanks

Posted (edited)

ohh is see

I posted that VL code for your reference only. as i've said its for Constant attribute extraction

and maybe you I should throw in the (vl-load-com) statement...

 

anyway you can try this...

 

 

(defun c:test (/ bnm blks cnt enxt entg)
  (setq bnm (cdr (assoc 2 (entget (car (entsel "\nSelect Block: ")))))
      blks (ssget "_X" (list (cons 2 bnm)'(66 . 1)) )cnt -1)
 (repeat (sslength blks)
   (setq enxt (entnext (ssname blks (setq cnt (1+ cnt))))
         entg (entget enxt))
   (while
    (= "ATTRIB" (cdr (assoc 0 entg)))
     (print (cdr (assoc 1 entg)))
     (setq enxt (entnext enxt)
                      entg (entget enxt))
     )
      )(princ)
   )

 

As you requested.. DXF codes :)

Edited by pBe
codes revised
Posted

It's marvillous . :)

 

Thank you so much for your kind replies, besides that, your hard work that you did for me.

 

Greatly appreciated.

 

Michaels.

Posted
ohh is see

I posted that VL code for your reference only. as i've said its for Constant attribute extraction

and maybe you I should throw in the (vl-load-com) statement...

 

anyway you can try this...

 

 

(defun c:test (/ bnm blks cnt enxt entg)
(setq bnm (cdr (assoc 2 (entget (car (entsel "\nSelect Block: ")))))
blks (ssget "_X" (list (cons 2 bnm)'(66 . 1)) )cnt -1)
(repeat (sslength blks)
(setq enxt (entnext (ssname blks (setq cnt (1+ cnt))))
entg (entget enxt))
(while
(= "ATTRIB" (cdr (assoc 0 entg)))
(print (cdr (assoc 1 entg)))
(setq enxt (entnext enxt)
entg (entget enxt))
)
)(princ)
)

 

As you requested.. DXF codes :)

 

I understand that this is only a test, but remember to check for entsel = nil. :wink:

Posted (edited)

oh my goodness you're right Renderman..

 

Here.. this is one way of preventing that.. :)

 

 
(defun c:test (/ [color=sienna]obj [/color] bnm blks cnt enxt entg)
[color=sienna](while (not (setq obj (entsel "\nSelect Block: ")))
   )
(cond    
[/color][color=sienna] ((setq bnm (cdr (assoc 2 (entget (car obj)))) cnt -1))
 (setq blks (ssget "_X" (list (cons 2 bnm)'(66 . 1)) ))
[/color]  
  (repeat (sslength blks)
  (setq enxt (entnext (ssname blks (setq cnt (1+ cnt))))
   entg (entget enxt))
   (while
   (= "ATTRIB" (cdr (assoc 0 entg)))
   (print (cdr (assoc 1 entg)))
    (setq enxt (entnext enxt)
     entg (entget enxt)))
      )
    [color=sienna])
[/color]   
[color=sienna]    (if (not blks)(princ "\nNo Block with attribute found: "))(princ)
[/color])

 

Thanks for the heads up buddy :D

Edited by pBe
error in code
Posted

I had fun with this one :D

 

[b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:DisplayAttribs [b][color=RED]([/color][/b] [b][color=BLUE]/[/color][/b] dxf ss [b][color=RED])[/color][/b]
 [i][color=#990099];; © Lee Mac 2010[/color][/i]

 [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] dxf [b][color=RED]([/color][/b][b][color=BLUE]lambda[/color][/b] [b][color=RED]([/color][/b] x l [b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] x l[b][color=RED]))))[/color][/b]

 [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ss [b][color=RED]([/color][/b][b][color=BLUE]ssget[/color][/b] [b][color=#a52a2a]"_+.:E:S"[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=RED](([/color][/b][b][color=#009900]0[/color][/b] [b][color=DARKRED].[/color][/b] [b][color=#a52a2a]"INSERT"[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=#009900]66[/color][/b] [b][color=DARKRED].[/color][/b] [b][color=#009900]1[/color][/b][b][color=RED]))))[/color][/b]
   [b][color=RED]([/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]lambda[/color][/b] [b][color=RED]([/color][/b] entity [b][color=BLUE]/[/color][/b] elist [b][color=RED])[/color][/b]
       [b][color=RED]([/color][/b][b][color=BLUE]while[/color][/b]
         [b][color=RED]([/color][/b][b][color=BLUE]not[/color][/b]
           [b][color=RED]([/color][/b][b][color=BLUE]eq[/color][/b] [b][color=#a52a2a]"SEQEND"[/color][/b]
             [b][color=RED]([/color][/b]dxf [b][color=#009900]0[/color][/b]
               [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] elist
                 [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b]
                   [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] entity
                     [b][color=RED]([/color][/b][b][color=BLUE]entnext[/color][/b] entity[b][color=RED])[/color][/b]
                   [b][color=RED])[/color][/b]
                 [b][color=RED])[/color][/b]
               [b][color=RED])[/color][/b]
             [b][color=RED])[/color][/b]
           [b][color=RED])[/color][/b]
         [b][color=RED])[/color][/b]
         [b][color=RED]([/color][/b][b][color=BLUE]terpri[/color][/b][b][color=RED])[/color][/b]
         [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=RED]([/color][/b]PadMiddle [b][color=RED]([/color][/b]dxf [b][color=#009900]2[/color][/b] elist[b][color=RED])[/color][/b] [b][color=RED]([/color][/b]dxf [b][color=#009900]1[/color][/b] elist[b][color=RED])[/color][/b] [b][color=#a52a2a]"."[/color][/b] [b][color=#009900]35[/color][/b][b][color=RED]))[/color][/b]
       [b][color=RED])[/color][/b]
     [b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]ssname[/color][/b] ss [b][color=#009900]0[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED])[/color][/b]
 [b][color=RED])[/color][/b]

 [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b]
[b][color=RED])[/color][/b]

[b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] PadMiddle [b][color=RED]([/color][/b] s1 s2 ch ln [b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]<[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]+[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strlen[/color][/b] s1[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strlen[/color][/b] s2[b][color=RED]))[/color][/b] ln[b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b]PadMiddle [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] s1 ch[b][color=RED])[/color][/b] s2 ch ln[b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] s1 s2[b][color=RED])[/color][/b]
 [b][color=RED])[/color][/b]
[b][color=RED])[/color][/b]

Posted
oh my goodness you're right Renderman..

 

Here.. this is one way of preventing that.. :)

 

Thanks for the heads up buddy :D

 

 

I've made the same mistake many times before; you're welcome :)

Posted

Thank you all gentlemen.

 

I still do not know how to deal with function *entnext* . I don't know why !!!!

 

Suppose that I have 3 Attributes in a block , for example - how could I extract them to a .txt file ?

 

many thanks.

 

Michaels

Posted

As a quick modification of my previous code:

 

[b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:DisplayAttribs [b][color=RED]([/color][/b] [b][color=BLUE]/[/color][/b] dxf ss fl [b][color=RED])[/color][/b]
 [i][color=#990099];; © Lee Mac 2010[/color][/i]

 [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] dxf [b][color=RED]([/color][/b][b][color=BLUE]lambda[/color][/b] [b][color=RED]([/color][/b] x l [b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] x l[b][color=RED]))))[/color][/b]

 [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ss [b][color=RED]([/color][/b][b][color=BLUE]ssget[/color][/b] [b][color=#a52a2a]"_+.:E:S"[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=RED](([/color][/b][b][color=#009900]0[/color][/b] [b][color=DARKRED].[/color][/b] [b][color=#a52a2a]"INSERT"[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=#009900]66[/color][/b] [b][color=DARKRED].[/color][/b] [b][color=#009900]1[/color][/b][b][color=RED]))))[/color][/b]
        [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] fl [b][color=RED]([/color][/b][b][color=BLUE]getfiled[/color][/b] [b][color=#a52a2a]"Select Output File"[/color][/b] [b][color=#a52a2a]""[/color][/b] [b][color=#a52a2a]"txt"[/color][/b] [b][color=#009900]1[/color][/b][b][color=RED]))[/color][/b]
        [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] fl [b][color=RED]([/color][/b][b][color=BLUE]open[/color][/b] fl [b][color=#a52a2a]"w"[/color][/b][b][color=RED]))[/color][/b]
   [b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]lambda[/color][/b] [b][color=RED]([/color][/b] entity [b][color=BLUE]/[/color][/b] elist [b][color=RED])[/color][/b]
       [b][color=RED]([/color][/b][b][color=BLUE]while[/color][/b]
         [b][color=RED]([/color][/b][b][color=BLUE]not[/color][/b]
           [b][color=RED]([/color][/b][b][color=BLUE]eq[/color][/b] [b][color=#a52a2a]"SEQEND"[/color][/b]
             [b][color=RED]([/color][/b]dxf [b][color=#009900]0[/color][/b]
               [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] elist
                 [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b]
                   [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] entity
                     [b][color=RED]([/color][/b][b][color=BLUE]entnext[/color][/b] entity[b][color=RED])[/color][/b]
                   [b][color=RED])[/color][/b]
                 [b][color=RED])[/color][/b]
               [b][color=RED])[/color][/b]
             [b][color=RED])[/color][/b]
           [b][color=RED])[/color][/b]
         [b][color=RED])[/color][/b]
         [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] [b][color=RED]([/color][/b]PadMiddle [b][color=RED]([/color][/b]dxf [b][color=#009900]2[/color][/b] elist[b][color=RED])[/color][/b] [b][color=RED]([/color][/b]dxf [b][color=#009900]1[/color][/b] elist[b][color=RED])[/color][/b] [b][color=#a52a2a]"."[/color][/b] [b][color=#009900]35[/color][/b][b][color=RED])[/color][/b] [b][color=#a52a2a]"\n"[/color][/b][b][color=RED])[/color][/b] fl[b][color=RED])[/color][/b]
       [b][color=RED])[/color][/b]
       [b][color=RED]([/color][/b][b][color=BLUE]close[/color][/b] fl[b][color=RED])[/color][/b]
     [b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]ssname[/color][/b] ss [b][color=#009900]0[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED])[/color][/b]
 [b][color=RED])[/color][/b]

 [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b]
[b][color=RED])[/color][/b]

[b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] PadMiddle [b][color=RED]([/color][/b] s1 s2 ch ln [b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]<[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]+[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strlen[/color][/b] s1[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strlen[/color][/b] s2[b][color=RED]))[/color][/b] ln[b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b]PadMiddle [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] s1 ch[b][color=RED])[/color][/b] s2 ch ln[b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] s1 s2[b][color=RED])[/color][/b]
 [b][color=RED])[/color][/b]
[b][color=RED])[/color][/b]

Posted

Thanks again and again Lee.

 

What is the use of "SEQEND" in the routine ?

 

And please tell me how can I understand the use of function *entnext* correctly in your routine and in general ?

 

Thank you so much

Posted

entnext merely steps through the drawing database, returning each entity that has been created in turn. (If there is no 'next' entity in the database, it returns nil).

 

When you create (or indeed entmake) an attributed block, the INSERT Entity is created, then the ATTRIBute entities are created, and finally a SEQEND entity is created to signal the end of subentity creation.

 

Hence, if you use entnext on an attributed INSERT, you will retrieve the entities which have been created following that INSERT, these are the ATTRIBute entities, then finally the SEQEND terminating entity. (If you then entnext the SEQEND, you will receive any entities that have been created following the attributed block).

 

The same is true of 3DPolylines, in which VERTEX entities are created following the POLYLINE entity. Then finally, a SEQEND entity is created.

 

You can visually see this construction using this tool I put togther.

 

Also, read up on entmake'ing such objects as Attributed INSERTs and POLYLINES.

Posted

Thank you so much Lee.

 

So could you please tell me what's wrong in my routine and it's none stop looping .of course by a mistake that I can't find .?

 

A very nice site by the way , wish you best of luck . :)

 

(defun c:out (/ f ss)
 (setq f (open "D://atts.txt" "w"))
 (if (and (setq ss (car (entsel "\nSelect Block: ")))
          (eq "INSERT" (cdr (assoc 0 (entget ss))))
          (= 1 (cdr (assoc 66 (entget ss))))
        )
   (progn
  (write-line
         (strcat (cdr (assoc 5 (entget ss)))  
  (while (not (eq "SEQEND" (cdr (assoc 0 (setq Lst (entget (setq Ents (entnext ss))))))))
               (cdr (assoc 2 Lst)) (cdr (assoc 1 Lst))
                            )
         )
   f)
   (close f))
   (princ "\n Nothings done")
   )
   (princ)
 )

Posted

The loop will never return false, as you are always looking at the first attribute (the entity following the block).

Posted

I couldn't get you well . So what should I do with it ?

Posted
I couldn't get you well . So what should I do with it ?

 

The loop test condition will never return false as the entnext entity being tested is always the first ATTRIBute following the INSERT entity, and hence the loop will continue endlessly.

Posted
Even not a close to my mind. :)

 

What do you mean?

 

I would suggest you re-read my post#14, and furthermore read the VLIDE Help File on entnext (the answer to your problem is there) - I could of course just give the answer (and in fact I already have in my earlier codes), but I figure you will learn more if you try to figure it out for yourself...

 

By the way you may want to reconstruct the write-line statement instead of trying to do everything in one statement.

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