Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

One attribute at two different locations inside of one block

56 REPLIES 56
Reply
Message 1 of 57
ivehabovic
12147 Views, 56 Replies

One attribute at two different locations inside of one block

Is there a way (or a “trick”) to have one attribute at two different locations inside of one block (

I want to avoid filling in the same text twice when this block is inserted or edited)?

Thanks,

iv

56 REPLIES 56
Message 2 of 57
pbejse
in reply to: ivehabovic

FIELDS

 

 

Message 3 of 57
Lee_Mac
in reply to: ivehabovic

This demonstrates how to link attributes between two different blocks, but the same method could be used to link two attributes within the same block.

Message 4 of 57
pbejse
in reply to: Lee_Mac


@Lee_Mac wrote:

This demonstrates how to link attributes between two different blocks, but the same method could be used to link two attributes within the same block......

 


 

Exactly...... I think i would have great difficulty explaining what i meant wihtout that demo you made.

 

Fancy seeing you on this parts Lee. Smiley Happy

 

 

 

Message 5 of 57
Lee_Mac
in reply to: pbejse


Exactly...... I think i would have great difficulty explaining what i meant wihtout that demo you made.

As they say, a picture is worth a thousand words Smiley Wink


Fancy seeing you on this parts Lee. Smiley Happy


I've actually been registered here for quite some time, but didn't visit too often. Its nice to see some familiar faces Smiley Happy

Message 6 of 57
ivehabovic
in reply to: Lee_Mac

Lee_Mac:

Thanks for the quick response. Your solution works with block that has been already inserted into dwg. I want similar behavior when I insert new block with attributes that have the same values.

Regards

iv

Message 7 of 57
Lee_Mac
in reply to: ivehabovic

Hi Iv,

 

You should be able to follow the same method as I have shown, but instead of selecting an attribute in another block, select an attribute in the same block.

 

Lee

Message 8 of 57
stevor
in reply to: ivehabovic

Another way would be to make a lisp to do the inserts and load the ATT values.
S
Message 9 of 57
Lee_Mac
in reply to: stevor

I posted the following code at theSwamp a while back, it will prompt for selection of a 'source' attribute, then prompt for multiple attributes to link to that source attribute using a field referencing the text string.

 

(defun c:attlink ( / *error* _ObjectID _Select acdoc att cmd str )
  ;; © Lee Mac 2011

  (defun *error* ( msg )
    (if cmd (setvar 'CMDECHO cmd))
    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
        (princ (strcat "\n** Error: " msg " **")))
    (princ)
  )

  (defun _ObjectID ( doc obj )
    (if (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
      (vlax-invoke-method (vla-get-Utility doc) 'GetObjectIdString obj :vlax-false)
      (itoa (vla-get-Objectid obj))
    )
  )
  
  (defun _Select ( msg pred / e ) (setq pred (eval pred))  
    (while
      (progn (setvar 'ERRNO 0) (setq e (car (nentsel msg)))
        (cond
          ( (= 7 (getvar 'ERRNO))
            (princ "\nMissed, Try again.")
          )
          ( (eq 'ENAME (type e))
            (if (and pred (not (pred e)))
              (princ "\nInvalid Object Selected.")
            )
          )
        )
      )
    )
    e
  )

  (setq acdoc (vla-get-activedocument (vlax-get-acad-object))
          cmd (getvar 'CMDECHO)
  )
  (setvar 'CMDECHO 0)

  (if
    (and
      (setq att
        (_Select "\nSelect Source Attribute: "
         '(lambda ( x ) (eq "ATTRIB" (cdr (assoc 0 (entget x)))))
        )
      )
      (setq str
        (strcat "%<\\AcObjProp Object(%<\\_ObjId "
          (_ObjectID acdoc (vlax-ename->vla-object att)) ">%).TextString>%"
        )
      )
    )
    (while
      (setq att
        (_Select "\nSelect Attribute to Link <Exit>: "
         '(lambda ( x ) (eq "ATTRIB" (cdr (assoc 0 (entget x)))))
        )
      )
      (vla-put-textstring (vlax-ename->vla-object att) str)
      (vl-cmdf "_.updatefield" att "")
    )
  )
  (setvar 'CMDECHO cmd) (princ)
)
(vl-load-com) (princ)

 

Message 10 of 57
orin4321
in reply to: ivehabovic

I noticed your question was never really answered.

 

I am having the same issue.  I have a single block with two sets of attributes, when both sets equal the same information.  How do you get rid of one set, or have a single value showing up in two different locations?  so you only have one definition to change.

 

selecting object/value in a field will only give you the default for the selected attribute.

Message 11 of 57
pbejse
in reply to: orin4321


@orin4321 wrote:

I noticed your question was never really answered.

 

 

selecting object/value in a field will only give you the default for the selected attribute.


The suggestions posted above is all about assigning the field value after the block is inserted  Besides you only need to do this once.

 

One known issue for this is when you modify the TARGET attribute the link will be broken. You could either use TET/MTEXT inside the block and assign the Filed value, that way it cannot be accidentally edited and break the link.  Works well if theres only 1 of this  block on the drawing. As the value is tied to an specific object ID and a copy of the block will also be updated.

 

As for  value  from ATTDEF object  prior to insertion.Im not sure it can be done  at least not that i know of. On new cad version perhaps.

 

 

Message 12 of 57
cfetherston
in reply to: ivehabovic

I know I'm reviving an old thread but I found a solution to what I understood to be the problem.

 

If you create the field entrys into the block that is inserted into then, go to drawing utilities>drawing properties>custom, and them delete the fields that you are inserting. Then insert the block into the drawing, the new block will recreate the fields and auto populate the attributes.

 

Not sure if that is what you were looking for, but it works great for inventor to auto cad conversions if you want the titleblock to transfer attributes. Especially into paperspace.

 

Cheers

Message 13 of 57

I have noticed that in order for the link between two attributes (using field text) to work there must be a visibility parameter in the block (and at least two visibility states) , otherwise the slave attribute merely displays the default value of the master, and not the EATTEDIT value.  Unfortunately having a visibility state only fixes the issue of linking one attribute value to another using field text, it does not work to link TEXT or MTEXT to the attribute (again it only links to the default value of the attribute).  

 

This leads me to believe that the feature is glitched and does not work properly.  

Message 14 of 57

Yes I would agree the field feature is not working properly, and I have yet to find a reasonable solution. When you insert a field into a block and link it to an attribute. If you select the 'value' field it will only show the default value, not the custom value of the field which I am sure is not what was intended here, as it almost seems pointless. In the creation of our title blocks the only way I have gotten it to work is has the duplicate values in a group outside of the title block.

 

This is really annoying because as I am sure many can attest to how you need to idiot proof this kind of thing. Complicated blocks that make workflow easier are not possible for use by your average user, and educating everyone constantly is not possible.

 

 

Message 15 of 57
StephenLydall
in reply to: Lee_Mac


@Lee_Mac wrote:

This demonstrates how to link attributes between two different blocks, but the same method could be used to link two attributes within the same block.


 

This doesn't actually work it's not a solution for the problem of having 2 instances of the same attribute in the same block.

Message 16 of 57
wispoxy
in reply to: StephenLydall

How is this not the solution? Please provide images or other so we can get on the same page.

 

The .gif shows exactly what's titled of this thread.

Message 17 of 57
StephenLydall
in reply to: wispoxy


@Anonymous wrote:

How is this not the solution? Please provide images or other so we can get on the same page.

 

The .gif shows exactly what's titled of this thread.


It isn't the solution because it doesn't work for the actual question posted. You would think it should work but it doesn't.

What is shown in the gif is not a single unified block.

When using a field within a block and linking it to an attribute associated with value, the results of the field after the block is compiled is the default value of the attribute and not the (dynamic)variable. There is no option to select the variable. Hence when you change the variable of the associated attribute it does not reflect the update in the field. Unfortunately I can't compile a .gif to demonstrate the issue. The resulting block is not dynamic, perhaps it's intended to work that way but it doesn't. Having spent many hours looking for a solution, I can confidently say that there is no way to reasonably achieve a block that when you update a variable within the block for it to display the update in more than one location within the same block, and I cannot stress enough how important this distinction is.

Message 18 of 57
wispoxy
in reply to: StephenLydall

Thank you for the detailed description.

Message 19 of 57
StephenLydall
in reply to: wispoxy

I have continued my search and experiments with regards to this particular problem, I have still not come up with method for achieving exactly or how I believe this feature should actually be working, however I have a way to have a attribute display itself in two locations within the same block that seems to function normally. The issue is that the link between the two attributes can be broken unwittingly by an ignorant or lazy user. Also the procedure required to achieve this is perhaps more evidence to the fact that the intended feature is bugged and really should be looked into by auto desk.

 

Procedure as follows:

 

Create 2 attributes that you require to show the same dynamic piece of text ATT1 and ATT2;

Fill in the fields for TAG & PROMPT on both attributes;

For ATT1 add a DEFAULT value;

For ATT2 leave the DEFAULT value blank;

Convert to Block testBlock;

Create MTEXT with field to > OBJECT > [select [testBlock]] > ATT1; copy the field expression to your clipboard; exit the field window;

EATTEDIT on block [testBlock];

In the value for ATT2 paste the field expression from your clipboard; it should be highlighted to indicate that it is a field;

Apply and close editor.

 

This will now work that when you update the value of ATT1 it will be updated to ATT2; the caveats however are:-

1) Should the user update the value of ATT2 then the link will be broken.

2) The value is not stored in the original block only in an instance of the block, meaning that to propagate this functionality to further blocks then the user has to copy this block and not insert a block using the insert function via block definition. Unfortunately this is because the field points to the block ID which doesn't exist in the block definition itself. Meaning the only way to create the link is after inserting the block and creating the ObjId.

 

Ideally what is needed for this to function properly is for this link to be achieved in definition of the block, but at the moment when linking a field (either from within a MTEXT or ATT) when selecting the Value property, the field points to the default value and not the variable specific to that instance of the block. There really needs to be a way to link field to the instanced variable.

 

Also it would be far better to use a field linked to MTEXT in this case rather than an attribute. The problem here is that because MTEXT values are not dynamic, linking the field to MTEXT means the link does not propagate to future blocks in that future blocks will pull their values from the original ObjId.

 

If it were possible to hide and ATT field from EATTEDIT list it would help, currently setting the attribute to invisible or constant hides the display of the attribute altogether and isn't an option. Preventing users who do not understand fields, blocks and other more complicated AutoCAD functions from editing links goes a long way toward maintaining drawing fidelity across the office.

 

 

 

 

 

Message 20 of 57

@StephenLydall

 

This was exactly what I found to be true, and probably the most comprehensive and coherent summary of this post.  I second everything you have said here, especially the following two statements:

 

"...it would be far better to use a field linked to MTEXT in this case rather than an attribute."

 

"There really needs to be a way to link field to the instanced variable." 

 

As for the latter statement, I feel as though this was the intent of the "Display value for block reference" check box in the field editor (see image below) however this seems to be glitched or at least does not function the way I expected.  

 

AttField.png

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost