Author Topic: Attribute change  (Read 12795 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Attribute change
« Reply #30 on: January 03, 2006, 10:19:33 PM »
Design question :

If you change the attribute value in the block definition in the BlockTable<collection> does it change all insert instances ?

Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

CAB

  • Global Moderator
  • Seagull
  • Posts: 10388
Re: Attribute change
« Reply #31 on: January 03, 2006, 11:06:16 PM »
I say no, the attribute values are unique to the INSERT.
Was that a trick question? :)

This is the way I think the routine is working
CASE 1
Code: [Select]
(vlax-for blk blks  ;  <---<<  this steps through the block collection
                           ;;  when *Model_Space or *Paper_Space is the block
   (vlax-for ent blk ; <----<<  this steps throught each item in model space and finds the INSERTS
                            ;;  then the attributes are updated <plain blocks with attributes>

CASE 2
Code: [Select]
(vlax-for blk blks  ;  <---<<  this steps through the block collection
                           ;;  when xref is the block
   (vlax-for ent blk ; <----<<  this steps throught each item in the xref and finds the INSERTS
                            ;;  then the attributes are updated <plain blocks with attributes>

CASE 3
Code: [Select]
(vlax-for blk blks  ;  <---<<  this steps through the block collection
                           ;;  when parentblock is the block
   (vlax-for ent blk ; <----<<  this steps throught each item in the parent and finds the INSERTS
                            ;;  then the attributes are updated <plain blocks with attributes>
I tested Case 3  to 3 levels deep & the attributes were updated.
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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10388
Re: Attribute change
« Reply #32 on: January 03, 2006, 11:12:50 PM »
Oh, I checked the actual xref drawing & the attributes are not updated. But Jeff new that already. :-)

So the Actual drawing of the two titleblocks will have to be updated with refedit or opened directly
and edited. Not a big deal as there are only two of them in this case.
But every thing in the drawings will be updated & the xref will be two, else you would have to
reload the xref to show the updated attributes. I guess that doesn't matter as they are reloaded
each time the drawing is opened, right?

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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Attribute change
« Reply #33 on: January 03, 2006, 11:19:33 PM »
I say no, the attribute values are unique to the INSERT.
Was that a trick question? :)


Yes, sort of <a trick question> ..
The answer you gave meant that you weren't tricked  though.  :kewl:
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Jeff_M

  • King Gator
  • Posts: 3977
  • C3D user & customizer
Re: Attribute change
« Reply #34 on: January 03, 2006, 11:24:22 PM »
OK, Jeff.
If I do it this way with (if (= (vla-get-islayout blk) :vlax-false)
the plain blocks with attributes are overlooked as they are within the
model space block.
Yes, I know.....which is why I said I'd use it with the (ssget "x" '((0 . "INSERT")(66 . 1))) to select the attributes in Model/Paper space.....this saves having to step through every object in a large drawing (native, filtered selection sets are faster than stepping through each MS/PS block)

However....if you want to turn your main routine into a function that also handles ObjectDBX docs to work on the Xrefs, then forget that since ODBX doesn't allow SelSets anyway.

I've got an idea I'll post here in a bit.

Jeff_M

  • King Gator
  • Posts: 3977
  • C3D user & customizer
Re: Attribute change
« Reply #35 on: January 04, 2006, 12:21:00 AM »
OK, here's a version that I believe will work with the Xrefs. I've not tested it so it may have faults but it appears sound to me.
Code: [Select]
See revised & tested code further on in this thread
« Last Edit: January 04, 2006, 12:54:32 PM by Jeff_M »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10388
Re: Attribute change
« Reply #36 on: January 04, 2006, 09:10:50 AM »
Good morning Jeff, had to go to bed.
Wow, new territory for me the ObjectDBX.
I tested and found this line (vla-saveas odbx file) caused an 'Error saving File'
I commented it out and the routine finished with the plain blocked changed but
the nested block & of course the xref were unchanged.

Do I need to do anything special to enable the ObjectDBX are is it automatic?
Still using ACAD2000 for this test.
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.

T.Willey

  • Needs a day job
  • Posts: 5238
Re: Attribute change
« Reply #37 on: January 04, 2006, 11:29:37 AM »
I remember hearing that using ObjectDBX with text, mtext or attributes has problems.  I think the problem was that they loose there alignment sometimes.  I remember trying to do an update title block routine with OBDX and ran into this, and it was confirmed with others one the another forum (acad customization at autodesk).  I think they said that Tony T. had a program to fix it, but that it wasn't available with later version of Acad.

My $00000.02
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5238
Re: Attribute change
« Reply #38 on: January 04, 2006, 11:39:15 AM »
Jeff,
Would your routine fail when it ran into an xref within an xref?
After thinking about it, I don't think that is a problem.

The only problem I can see is if you have 3 (or more) drawings that reference each other, so a continout loop will occur.
Drawing A -> References Drawing B
Drawing B -> References Drawing C
Drawing C -> References Drawing A

I know you could take care of this it would just take more coding, but that is the only issue I can see, other than the one I pointed out about the alignment issue.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Biscuits

  • Bull Frog
  • Posts: 464
Re: Attribute change
« Reply #39 on: January 04, 2006, 12:04:54 PM »
Wow I sure got some brain cell to fire up! None  of them mine.

Routine is working great CAB!

Thanks again

Jeff_M

  • King Gator
  • Posts: 3977
  • C3D user & customizer
Re: Attribute change
« Reply #40 on: January 04, 2006, 12:52:03 PM »
OK, Good Morning Alan & Tim.....'twas a long night with an ill cat....
I did find an error in the RELOAD portion for the xref:
Code: [Select]
    (vl-catch-all-apply '(lambda () (vla-reload (vla-item (vla-get-blocks doc) (vla-get-name ent)))))
is what it needs to be.

Alan, if it makes it past the (setq odbx....) without error then you already have ObjectDBX registered. I will check if there is an issue with the SaveAs in R2000......wait, if the SYSVAR XLOADCTL is set to anything other than 2 it will probably cause this. Here's a version that first Unloads the Xref so it can be edited than Reloads it.
Code: [Select]
;;=======================[ cUpdate.lsp ]=======================
;;; Author: Copyright© 2006 Charles Alan Butler
;;; Version:  1.11jm Jan. 03, 2006
;;; Purpose: To update attributes in a drawing, nested blocks & xref
;;;          Ignores locked or Frozen layers
;;; Sub_Routines: -None
;;; Requirements: - Acad Versions 2000-2002 must have ObjectDBX registered before running
;;; Returns: -None
;;;==============================================================
;; ObjectDBX added to edit Xrefs by Jeff Mishler
;;
(defun c:cupdate (/ ss ent obj att blks newtext taglist)
  (setq newtext "2006 C-n-R CORPORATION"
taglist '("COPYRIGHT" "COPYRIGHTYEAR")
  )
  ;; converted majority to function for recursive use with xrefs, jm
  (defun process_atts (doc / file odbx)
    (vlax-for blk (vla-get-blocks doc)
      (vlax-for ent blk
(if (and (vlax-property-available-p ent 'hasattributes)
(= (vla-get-hasattributes ent) :vlax-true)
    )
  (progn
    (foreach att (vlax-invoke ent 'getattributes)
      (if (member (vla-get-tagstring att) taglist)
(vl-catch-all-apply '(lambda ()
       (vla-put-textstring att newtext)
       ))
;;added catch-all to catch possible locked layer error, jm
      )
    )
  )
)
(if (and (vlax-property-available-p ent 'path)
(setq file (findfile (vla-get-path ent)))
(setq xrblk (vla-item (vla-get-blocks doc) (vla-get-name ent)))
)
  (progn
    (vla-unload xrblk)
    (setq odbx (if (< (atoi (setq oVer (substr (getvar "acadver") 1 2))) 16)
(vla-GetInterfaceObject (vlax-get-acad-object) "ObjectDBX.AxDbDocument")
(vla-GetInterfaceObject (vlax-get-acad-object) (strcat "ObjectDBX.AxDbDocument." oVer))
))
    (vla-open odbx file)
    (process_atts odbx)
    (vl-catch-all-apply '(lambda () (vla-saveas odbx file)))
    (vlax-release-object odbx)
    (vl-catch-all-apply '(lambda () (vla-reload xrblk)))
    )
  );;
      )
    )
  )
  (process_atts (vla-get-activedocument (vlax-get-acad-object)))
  (princ)
)
(prompt "\nCopyright Update Loaded, Enter cupdate to run.")
(princ)

Tim, the alignment problem is only with Attributes and only when you change the alignment. Just changing the value does not cause a problem, IIRC. I'm pretty sure that Autocad already prevents you from creating the Xrefs in a loop. Although a problem is encountered with nested Xrefs, which is why the Reload is wrapped by the (vl-catch-all-apply).....you can't reload a nested xref, only the parent xref.

T.Willey

  • Needs a day job
  • Posts: 5238
Re: Attribute change
« Reply #41 on: January 04, 2006, 01:15:27 PM »
Tim, the alignment problem is only with Attributes and only when you change the alignment. Just changing the value does not cause a problem, IIRC.
I just tested it, and it doesn't show right after you change the text also.  I change it with this routine.
Code: [Select]
(defun c:TestAttributes (/ dbxApp File)

(setq dbxApp (vla-GetInterfaceObject (vlax-get-Acad-Object) "ObjectDBX.AxDbDocument.16"))
(setq File (getfiled "" "" "dwg" 4))
(vla-Open dbxApp File)
(vlax-for i (vla-get-PaperSpace dbxApp)
 (if
  (and
   (= (vla-get-ObjectName i) "AcDbBlockReference")
   (= (vla-get-Name i) "3M-BORDER-E1")
  )
  (foreach ii (vlax-invoke i 'GetAttributes)
   (vla-put-TextString ii "This is a test")
  )
 )
)
(vla-SaveAs dbxApp File)
(vlax-release-object dbxApp)
(setq dbxApp nil)
(princ)
)
Attributes that are supposed to be middle justified, get change to show left justified.  You have to edit the attribute again to have it show the right justification again.  You can just edit the text with "ddatte" but you have to run that and actually change the text to have it update to the correct justification.

ps.  The code above will only work with A2k4 or above because of the call to ObjectDBX's interface object.
I'm pretty sure that Autocad already prevents you from creating the Xrefs in a loop.
This is true with only two references.  I'm talk about three (which I don't think would happen, but just wanted to point it out).
B -> into A
then A can not go into B because of circle reference.
But
A -> into C
C -> into B
B-> into A
This instance would not cause a circle reference because you are going from A to B to C then back to A then back into B etc...
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10388
Re: Attribute change
« Reply #42 on: January 04, 2006, 01:37:09 PM »
That version worked on the plain blocks & the xref with XLOADCTL is set to 1
using ACAD2000 and no errors reported.

However the nested block attributes were not updated.
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.

Jeff_M

  • King Gator
  • Posts: 3977
  • C3D user & customizer
Re: Attribute change
« Reply #43 on: January 04, 2006, 02:25:36 PM »
I'm talk about three (which I don't think would happen, but just wanted to point it out).
B -> into A
then A can not go into B because of circle reference.
But
A -> into C
C -> into B
B-> into A
This instance would not cause a circle reference because you are going from A to B to C then back to A then back into B etc...
I just tried to do this and got a message box that "this was creating a circular reference, would I like to continue", I replied Yes and this is the result:
Code: [Select]
Command: _xref
Attach Xref "B": C:\Base Maps\Jeffs Test Files\XRefTest\B.dwg
"B" loaded.

Attach Xref "C": C:\Base Maps\Jeffs Test Files\XRefTest\C.dwg
"C" loaded.

Breaking circular reference from "C" to "current drawing".
All it did was remove the A reference from C.......So no, Acad keeps circular references from ever occurring.
Quote from: T.Willey
and it doesn't show right after you change the text also.
Right you are, I stand corrected.

Alan, the nested blocks in the drawing or in the Xref or all of them? Could you post the test drawings you are running this on?

And FWIW, based on what Biscuits originally posted, there isn't a need for the Xref portion anyway since they opted to NOT use them...........have we been trying to solve a problem that doesn't exist?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10388
Re: Attribute change
« Reply #44 on: January 04, 2006, 02:38:56 PM »
Sorry Jeff, the nested blocks were updated, just needed a regen to show it.

I guess I/we got off focus on the xref. Great solution though. 8-)

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