Author Topic: block=block - diesel fields do not update  (Read 8152 times)

0 Members and 1 Guest are viewing this topic.

owenwengerd

  • Bull Frog
  • Posts: 451
Re: block=block - diesel fields do not update
« Reply #15 on: September 11, 2012, 01:58:03 PM »
That helps clarify what you're doing.

If it's only the drawing number and sheet number attributes that you're updating, I recommend to just write a small lisp function to do that, using hardcoded tag names and new values. You can find all kinds of examples here at the swamp and on the Autodesk forums of lisp code for changing the value of an existing attribute. Here is one I found via Google.

If you don't need to automate the process and if your old values are also fields that can be easily identified via search string, you could probably use the FIND command to replace the old value with the new.

Hopefully that helps.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: block=block - diesel fields do not update
« Reply #16 on: September 12, 2012, 04:14:39 PM »
Below is the explanation copied from my response to your email, posted here for the benefit of others following this thread:

Quote
...to provide a quick explanation for the result that you are receiving:

Attribute references contained within a block reference are considered as separate from the associated block definition (this is to enable the attribute references to hold different values across multiple block references); when you redefine a block in the drawing, the block reference geometry is updated to reflect the updated block definition, however, the attribute references are not altered in any way (since they become separate from the definition when a reference is inserted).

The use of ATTSYNC will only update the positions & properties of the attribute references and possibly add or remove attribute references that are either present in the definition and not present in the block reference, or vice versa; the values of the attribute references are not altered in any way.

Since the Field Expressions in your modified block definition are located in the default values for the attribute definitions, these default values will not be applied to existing block references when the block is redefined, and furthermore the values of the attributes references will not be updated following an ATTSYNC operation, as described above.

A potential solution would be to use a custom program to update the values of the necessary attribute references to use the default values held by the associated attribute definitions within the block definition, or even hard-code these updated values in the program itself.

LE3

  • Guest
Re: block=block - diesel fields do not update
« Reply #17 on: September 12, 2012, 04:39:56 PM »
<SideQuestion>
Master Lee, how much do you charge per hour? doing lisp or it is per application? or?
<SideQuestion>

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: block=block - diesel fields do not update
« Reply #18 on: September 12, 2012, 07:07:19 PM »
I'm sure you know me better than to think I would discuss such matters on a public forum Luis  :-)

airportman

  • Newt
  • Posts: 37
  • i customize when required
Re: block=block - diesel fields do not update
« Reply #19 on: September 12, 2012, 11:12:33 PM »
Just to clarify. I was not looking for someone to write me some code. I can write the code.
I was looking for some information that might be beyond my knowledge.
a few things I understand here:

LISP
ODBX (with lisp)
Diesel expressions

where I think this might be a bit more complicated and could have a different outcome, is if I knew how to access the OBJECT ID, to get what i'm looking for from the diesel expression.

I thank you Lee for having a look. I can make it work from here, and I will post it when I got it.

Perception is a state of mind  -/ Twitter = @hochanz -/ Intel i7 - 3.07GHz -/ 12GB Ram -/ Nvidia Quadro FX 1800

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: block=block - diesel fields do not update
« Reply #20 on: September 13, 2012, 07:12:15 AM »
I think the issue you're running into is the working around how AttSync/BAttMan-Sync operates.

If a reference to the block contains an attribute named as per the definition's AttDefs, then that attribute will only be modified to match the properties of the AttDef.

However, if the block reference does not contain an Attrib matching one of the AttDef's - it is created using the default value of the AttDef.

So a "quick-fix" solution for you would be to rename the AttDef inside your new TB to something else that what the same tagname in the old TB was. Then insert, redefine & attsync. This should then delete the old Attrib with the old tagname and re-create the new Attrib with the new tagname and new default value.

An alternative method would be to recreate the field expression through lisp, see other post.

Also if you need to find the ObjectID of an entity so you can use it inside a field expression you build from lisp, then look into the entity's ActiveX object:
Code - Auto/Visual Lisp: [Select]
  1. ;; Command to place a field showing the length of a picked entity
  2. (defun c:FieldLength  (/ en eo pt)
  3.   (vl-load-com) ;Ensure VLisp COM extensions are loaded
  4.   (if (setq en (entsel "Pick an entity to show its length: "))
  5.     (if (and (setq eo (vlax-ename->vla-object (car en))) ;Convert the EName to a VLA-Object
  6.              (vlax-property-available-p eo 'Length)) ;Check if the object has a Length property
  7.         (if (setq pt (getpoint "\nPick point at which to place field text: "))
  8.             (command "._MText" pt "_Width" 0.0
  9.                      (strcat "%<\\AcObjProp Object(%<\\_ObjId "
  10.                              (itoa (vla-get-ObjectID eo)) ;Include the ObjectID
  11.                              ">%).Length \\f \"%lu6\">%")
  12.                      "")
  13.         (prompt "\nNo point picked, exiting."))
  14.       (prompt "\nThat objtct does not have a length, exiting."))
  15.     (prompt "\nNothing selected, exiting."))
  16.   (princ))
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: block=block - diesel fields do not update
« Reply #21 on: September 13, 2012, 08:41:15 AM »
I agree, forget attributes & use fields directly.
The old method was to use Rtext.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

airportman

  • Newt
  • Posts: 37
  • i customize when required
Re: block=block - diesel fields do not update
« Reply #22 on: September 14, 2012, 01:23:43 PM »
And following on the advice of many (in particular IRNEB).
I modified the new TB with new TAGS (containing the diesel expressions).
I rechecked my code, that was throwing up a NIL response for some reason
I added (ARXLOAD "BATTMAN")
I added (acet-attsync var1)
I called a simple "qsave"
I created a script file (for use with ScriptPro 2 - see here: http://labs.blogs.com/its_alive_in_the_lab/2010/10/adn-plugin-of-the-month-scriptpro-for-autocad-now-available.html)

And then the rather simple routine:

Code: [Select]
(defun blockup2 (/ newblk2 redefblk2 ) ;block replace
(vl-load-com)
  (setvar "tilemode" 1)
  (setq newblk2 "SUN_TBD_ISO")                            ;set block name
    (progn               ;do the following:
  ;prepare the block name string using the blockname=blockname format
        (setvar "attreq" 0)                           ;turn attribute request off
  (setq redefblk2 (strcat newblk2 "=M:/CADD Files/LISP_MODS/SUN_TBD_ISO.dwg"))
  (command "-insert" redefblk2 "0,0" "" "" "" );insert an instance of the re-defined block at 0,0
  (command "zoom" "e")                        ;zoom extents
  (command "erase" "l" "")                    ;erase the just-inserted block (leaving an updated block reference)
  (command "zoom" "e")                        ;zoom previous
        (setvar "attreq" 1)                           ;turn attribute requesting back on
        (ARXLOAD "BATTMAN")
        (acet-attsync newblk2)                         ;synchronize attributes
)
(COMMAND ".QSAVE")
  (PRINC)
)
(blockup2)

All said and done.
It worked great.
Thank you (I plan to look more into the OBJECT ID)
Perception is a state of mind  -/ Twitter = @hochanz -/ Intel i7 - 3.07GHz -/ 12GB Ram -/ Nvidia Quadro FX 1800

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: block=block - diesel fields do not update
« Reply #23 on: September 15, 2012, 01:27:32 AM »
Glad you got it working  ;)
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

snddd2000

  • Guest
Re: block=block - diesel fields do not update
« Reply #24 on: December 18, 2012, 09:33:21 AM »
(command "-insert" redefblk2 "0,0" "" "" "" );insert an instance of the re-defined block at 0,0
Have any vlisp code instead of this code?not use "command"
thanks

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: block=block - diesel fields do not update
« Reply #25 on: December 18, 2012, 09:41:39 AM »
(command "-insert" redefblk2 "0,0" "" "" "" );insert an instance of the re-defined block at 0,0
Have any vlisp code instead of this code?not use "command"

Code - Auto/Visual Lisp: [Select]
  1.     (vlax-3D-point 0.0 0.0)
  2.     redefblk2
  3.     1.0
  4.     1.0
  5.     1.0
  6.     0.0
  7. )

snddd2000

  • Guest
Re: block=block - diesel fields do not update
« Reply #26 on: December 18, 2012, 08:01:28 PM »
thanks lee,
the redefblk2="block-name=file-name",but get an error "Automation error",
if active-document is not  exist the same block, then use vla-insertblock and redefblk2="file-name" is ok.
if existed the same name block, then use vla-insertblock and redefblk2="block-name=file-name" is not working.
have any solutions? or no way. this block is HasAttributes
thanks
« Last Edit: December 18, 2012, 08:52:06 PM by snddd2000 »

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: block=block - diesel fields do not update
« Reply #27 on: December 19, 2012, 08:10:22 AM »
The InsertBlock method will require either a block name (if the block definition already exists in the Block Collection of the Document calling the method), or a filepath to the drawing containing the block definition.

If the full filepath is used, the InsertBlock method will always source the block definition from the external drawing, automatically redefining the block if it already resides in the Block Collection; hence the 'block-name=file-name' format is not required.

snddd2000

  • Guest
Re: block=block - diesel fields do not update
« Reply #28 on: December 19, 2012, 09:48:23 PM »
Thanks a lot, today i try this way, after read your reply, it is OK.
I confused the day before yesterday, i tried the same way, but it did not work. May be other errors caused
After all, eventually it is OK , thanks again.
« Last Edit: December 19, 2012, 09:55:32 PM by snddd2000 »

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: block=block - diesel fields do not update
« Reply #29 on: December 21, 2012, 05:49:14 PM »
Excellent, I'm glad that you understood my explanations  :-)