Get attribute values

Get attribute values

Anonymous
Not applicable
1,261 Views
12 Replies
Message 1 of 13

Get attribute values

Anonymous
Not applicable

I've been trying to put together two routines, one to assign a variable to each of the attribute values within a selected block; and the other to assign a variable to each of the attribute values within a block (which the user will specify by an attribute value). These routines are for one specific block which has four attributes.

The purpose of the routine is to use the attribute values on our title block.

The first routine would select a block and then assign a value to the attributes: NOTE#, NOTE, ANSWER and SKETCH

The second routine would prompt the user for a Note Number (NOTE#) and then assign a value to the attributes: NOTE, ANSWER and SKETCH from the block with the specified note number.

I've been working on this for a little while now and have come to the realization that I'm going to need some help

 

Thanks in advance,

Larry

0 Likes
Accepted solutions (1)
1,262 Views
12 Replies
Replies (12)
Message 2 of 13

hmsilva
Mentor
Mentor

Hi Larry,

 

It would be easier to help, if you post both codes, and a sample .dwg...

 

Henrique

EESignature

0 Likes
Message 3 of 13

Anonymous
Not applicable

Hi Henrique,

I've been working on the routine this morning and I got the first routine to work. Below is the code.

Now I need to get the second routine to work, the one where the values are retrieved from a block with a certain note number. I haven't even tried to compile this routine yet.

 

(DEFUN C:GATTV()

(SETVAR "CMDECHO" 0)

(SETQ H(SSGET))
(SETQ I(ENTGET(SSNAME H 0)))
(SETQ ENAME(CDR(ASSOC -1 I)))
(SETQ F(ENTGET ENAME))
(SETQ TNAM(CDR(ASSOC 0 F)))
(IF(= TNAM "INSERT")(PROGN
(SETQ ENAME1(ENTNEXT ENAME))
(SETQ EN1(ENTGET ENAME1))
(SETQ NOTNUM(CDR(ASSOC 1 EN1)))
(SETQ ENAME2(ENTNEXT ENAME1))
(SETQ EN2(ENTGET ENAME2))
(SETQ NOT(CDR(ASSOC 1 EN2)))
(SETQ ENAME3(ENTNEXT ENAME2))
(SETQ EN3(ENTGET ENAME3))
(SETQ ANS(CDR(ASSOC 1 EN3)))
(SETQ ENAME4(ENTNEXT ENAME3))
(SETQ EN4(ENTGET ENAME4))
(SETQ SK(CDR(ASSOC 1 EN4)))
))

(PRINC))

0 Likes
Message 4 of 13

Anonymous
Not applicable

What I'm hoping to do with the second routine is to run it in paper space, even though the blocks are in model space.

0 Likes
Message 5 of 13

hmsilva
Mentor
Mentor

@Anonymous wrote:

What I'm hoping to do with the second routine is to run it in paper space, even though the blocks are in model space.


Post a sample .dwg with the blocks...

The block in model space, and the 'Note Number' in a layout...

 

Henrique

EESignature

0 Likes
Message 6 of 13

Anonymous
Not applicable

sorry, forgot to add the drawing

 

the purpose of this is to be able to add drawing notes to the title block

0 Likes
Message 7 of 13

hmsilva
Mentor
Mentor

Hi Larry,

 

in model we have a dynamic block 'NOTE_FLAG1' with four attributes, NOTE#, NOTE, ANSWER and SKETCH.
In a layout we have a dynamic block 'NOTE#' with two attributes, NOTE and ANSWER.

 

So, let's see if I have understood.

you need to select the 'NOTE_FLAG1' in model, store the att values, select the 'NOTE#' in a layout, and copy NOTE# to NOTE, and ANSWER to ANSWER, I'm correct?

 

Henrique

EESignature

0 Likes
Message 8 of 13

Anonymous
Not applicable

Very close

Although I haven't added it yet, the NOTE# block will be inserted with this routine.

So, you would select the 'NOTE_FLAG1' in model and store the attribute values.

Then in paper space the NOTE# block would be inserted.

At that point the value of NOTE# from the block NOTE_FLAG! will be added as the attribute for block NOTE#, and the value of NOTE from the block NOTE_FLAG1 will be written to the tiltle block.

Having two NOTE#'s may be making things a bit confusing.

The values from ANSWER and SKETCH are being retrieved but not being used at this point.

 

I hope I didn't confuse you more

0 Likes
Message 9 of 13

hmsilva
Mentor
Mentor

Hi Larry,

 

quick and dirty, and as a starting point.

Assumes "NOTE#" definition already exists, and I have declared 'att_lst' as a local variable, if you're gonna need the other attribute values for a later use, we'll have to add that in this code...

 

(vl-load-com)
(defun c:demo ( / att_lst atts atts1 obj obj1 pt s1 tab)
  (if (and
        (= (getvar "tilemode") 0)
        (= (getvar "cvport") 1)
      )
    (if (setq pt (getpoint "\nSpecify \"NOTE#\" insertion point: "))
      (progn
        (setq tab (getvar 'CTAB))
        (setvar 'CTAB "Model")
        (if (and (setq s1 (ssget "_+.:E:S" '((0 . "INSERT") (66 . 1))))
                 (setq obj (vlax-ename->vla-object (ssname s1 0)))
                 (eq (vla-get-effectivename obj) "NOTE_FLAG1")
            )
          (progn
            (setq atts (vlax-safearray->list (vlax-variant-value (vla-getattributes obj))))
            (foreach att atts
              (setq att_lst (cons (cons (vla-get-tagstring att) (vla-get-textstring att)) att_lst))
            )
            (setvar 'CTAB tab)
            (setq obj1 (vlax-invoke
                         (vlax-get-property
                           (vla-get-activedocument (vlax-get-acad-object))
                           'paperspace
                         )
                         'insertblock
                         pt
                         "NOTE#"
                         1.0
                         1.0
                         1.0
                         0.0
                       )
            )
            (setq atts1 (vlax-safearray->list (vlax-variant-value (vla-getattributes obj1))))
            (foreach att atts1
              (if (eq (vla-get-tagstring att) "NOTE")
                (vla-put-textstring att (cdr (assoc "NOTE#" att_lst)))
              )
            )
          )
          (princ "\n\"NOTE_FLAG1\" not selected...")
        )
      )
    )
    (princ "\nYou'll need to be in paper space to run this code... ")
  )
  (princ)
)

 

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 10 of 13

Anonymous
Not applicable

That worked perfectly for inserting the "NOTE#" block with the note number

Now, I need to add this  (COMMAND "MTEXT" P1 "H" "0.1" "W" "3.65" NOT "")  to the routine. Where NOT is the value of the NOTE attribute from the block "NOTE_FLAG1"

I'll set the P1 variable

0 Likes
Message 11 of 13

hmsilva
Mentor
Mentor

@Anonymous wrote:

That worked perfectly for inserting the "NOTE#" block with the note number

Now, I need to add this  (COMMAND "MTEXT" P1 "H" "0.1" "W" "3.65" NOT "")  to the routine. Where NOT is the value of the NOTE attribute from the block "NOTE_FLAG1"

I'll set the P1 variable


As I said earlier

'Quick and dirty, and as a starting point.

Assumes "NOTE#" definition already exists...'

 

We'll have to test if "NOTE#" is already defined in dwg, if not, test if is found in SFSP...

 

(vl-load-com)
(defun c:demo (/ att_lst atts atts1 obj obj1 pspace pt s1 tab)
  (if (and
        (= (getvar "tilemode") 0)
        (= (getvar "cvport") 1)
      )
    (if (setq pt (getpoint "\nSpecify \"NOTE#\" insertion point: "))
      (progn
        (setq tab (getvar 'CTAB))
        (setvar 'CTAB "Model")
        (if (and (setq s1 (ssget "_+.:E:S" '((0 . "INSERT") (66 . 1))))
                 (setq obj (vlax-ename->vla-object (ssname s1 0)))
                 (eq (vla-get-effectivename obj) "NOTE_FLAG1")
            )
          (progn
            (setq atts (vlax-safearray->list (vlax-variant-value (vla-getattributes obj))))
            (foreach att atts
              (setq att_lst (cons (cons (vla-get-tagstring att) (vla-get-textstring att)) att_lst))
            )
            (setvar 'CTAB tab)
            (setq pspace (vla-get-paperspace (vla-get-activedocument (vlax-get-acad-object))))
            (setq obj1 (vlax-invoke
                         pspace 'insertblock pt "NOTE#" 1.0 1.0 1.0 0.0)
            )
            (setq atts1 (vlax-safearray->list (vlax-variant-value (vla-getattributes obj1))))
            (foreach att atts1
              (if (eq (vla-get-tagstring att) "NOTE")
                (vla-put-textstring att (cdr (assoc "NOTE#" att_lst)))
              )
            )

            (setq
              obj (vla-addmtext pspace (vlax-3d-point (polar pt 0.435667 0.319844)) 3.7 (cdr (assoc "NOTE" att_lst)))
            )
            (vla-put-height obj 0.1)
            (vla-put-width obj 3.65)
          )
          (princ "\n\"NOTE_FLAG1\" not selected...")
        )
      )
    )
    (princ "\nYou'll need to be in paper space to run this code... ")
  )
  (princ)
)

 

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 12 of 13

Anonymous
Not applicable

Ok Henrique,

I added the coding I needed to complete the routine.

Thank you very much for all your help. I definitely couldn't have done it without you.

 

Regards,

Larry

0 Likes
Message 13 of 13

hmsilva
Mentor
Mentor
Accepted solution

You're welcome, Larry!
Glad I could help

Henrique

EESignature

0 Likes