+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 16
  1. #1
    Full Member
    Computer Details
    iTijn's Computer Details
    Operating System:
    XP
    Computer:
    Dell Precision M4300
    Using
    AutoCAD 2010
    Join Date
    Apr 2007
    Posts
    60

    Idea change layer of block-attribute reference

    Registered forum members do not see this ad.

    Can someone set me of in the right direction?

    I'm trying to make a button to change the layer of the attribute in a block reference.
    I can do it manually with eattedit but this command doesn't allow the <_-command > format.

    Any suggestions how to approach this?

  2. #2
    Senior Member kpblc's Avatar
    Using
    AutoCAD 2005
    Join Date
    May 2006
    Location
    Russia, St-Petersburg
    Posts
    317

    Default

    You can do it by lisp. But there is one more qestion exist - do you want to change block definition or block references? Or both of them? In case of your answer the solving will be different.
    All I say is only my opinion.

  3. #3
    Forum Deity
    Using
    Civil 3D 2008
    Join Date
    Sep 2006
    Location
    Pittsburgh, PA, USA
    Posts
    3,581

    Default

    Try -attedit instead.
    Last edited by lpseifert; 26th Apr 2007 at 09:14 pm.

  4. #4
    Super Member ASMI's Avatar
    Using
    AutoCAD 2008
    Join Date
    Nov 2005
    Location
    Oceanus Procellarum, Moon
    Posts
    1,427

    Default

    It's imposible to change attribute layer with (command. Try something like this:

    Code:
    (defun c:atlay(/ curAtt samObj wLay)
      (vl-load-com)
      (setq curAtt T)
      (if
        (setq samObj
    	   (entsel
    	     "\nPick object to select layer > "))
        (progn
          (setq wLay(cdr(assoc 8(entget(car samObj)))))
          (princ
    	(strcat "\nYou select layer: " wLay))
          (while curAtt
    	(setq curAtt
    	       (nentsel
    		 "\nPick Attribute ot Right Click to quit > "))
    	(if curAtt
    	  (progn
    	    (setq curAtt(vlax-ename->vla-object(car curAtt)))
    	     (if
    	       (= "AcDbAttribute"(vla-get-ObjectName curAtt))
    		(if
    		  (vl-catch-all-error-p
    		    (vl-catch-all-apply
    		      'vla-put-Layer(list curAtt wLay)))
    		   (princ "\nCan't change layer. Attribute on locked layer! ")
    		  ); end if
    	      (princ "\nThis isn't attribute reference! ")
    	      ); end if
    	    ); end progn
    	  ); end if
    	); end while
          ); end progn
        ); end if
      (princ)
      ); end of c:atlay
    Multiple changing also possible, but need to add several lines of code.

  5. #5
    Super Member ASMI's Avatar
    Using
    AutoCAD 2008
    Join Date
    Nov 2005
    Location
    Oceanus Procellarum, Moon
    Posts
    1,427

    Default

    Look at http://www.cadtutor.net/forum/showthread.php?t=13270
    ***** editing *****
    The link above doesn't work any more -the target thread is moved right here.
    Fuccaro
    Last edited by fuccaro; 26th Apr 2007 at 10:13 pm.

  6. #6
    Senior Member
    Computer Details
    VVA's Computer Details
    Operating System:
    Windows 7
    CPU:
    Intel Core i5-2400
    RAM:
    8 Gb
    Graphics:
    Nvidia Quadro 600
    Primary Storage:
    Seagate 500 GB + WD 750 GB
    Monitor:
    Philips 27"
    Using
    AutoCAD 2013
    Join Date
    Dec 2006
    Location
    Minsk, Belarus
    Posts
    401

    Default

    Code:
    (defun mydcl (zagl info-list / fl ret dcl_id)
        (vl-load-com)
        (if (null zagl)
            (setq zagl "Select")
        ) ;_ end of if
        (setq fl (vl-filename-mktemp "mip" nil ".dcl"))
        (setq ret (open fl "w"))
        (mapcar '(lambda (x) (write-line x ret))
                (list "mip_msg : dialog { "
                      (strcat "label=\"" zagl "\";")
                      " :list_box {"
                      "alignment=top ;"
                      "width=51 ;"
                      (if (> (length info-list) 26)
                          "height= 26 ;"
                          (strcat "height= " (itoa (+ 3 (length info-list))) ";")
                      ) ;_ end of if
                      "is_tab_stop = false ;"
                      "key = \"info\";}"
                      "ok_cancel;}"
                ) ;_ end of list
        ) ;_ end of mapcar
        (setq ret (close ret))
        (if (setq dcl_id (load_dialog fl))
            (if (new_dialog "mip_msg" dcl_id)
                (progn
                    (start_list "info")
                    (mapcar 'add_list info-list)
                    (end_list)
                    (set_tile "info" "0")
                    (setq ret (car info-list))
                    (action_tile "info" "(setq ret (nth (atoi $value) info-list))")
                    (action_tile "cancel" "(progn(setq ret nil)(done_dialog 0))")
                    (action_tile "accept" "(done_dialog 1)")
                    (start_dialog)
                ) ;_ end of progn
            ) ;_ end of if
        ) ;_ end of if
        (unload_dialog dcl_id)
        (vl-file-delete fl)
        ret
    )
    ;;;================================================================================
    ;;;Written By Michael Puckett. 
    ;;;(setq all_layers (tablelist "LAYER"))
    (defun tablelist (s / d r)
      (while (setq d (tblnext s (null d)))
        (setq r (cons (cdr (assoc 2 d)) r))
      )     
    )     
    (defun C:CHATTLAY ( / *error* lay att ed blk blkdef doc)
      (vl-load-com)
      (setq doc (vla-get-activedocument(vlax-get-acad-object)))
      (if (setq lay (mydcl "Select layer" (acad_strlsort (tablelist "LAYER"))))
        (progn
          (while (setq att (nentselp "\nSelect attribute <exit>:"))
     (if (= (cdr(assoc 0 (setq ed (entget(setq att(car att)))))) "ATTRIB")
       (progn
         (setq att (vlax-ename->vla-object att))
         (setq blk (vla-objectidtoobject doc (vla-get-ownerid att)))
         (setq blkdef (vla-item (vla-get-blocks doc)(vla-get-name blk)))
                (vlax-for itm blkdef
           (if (and (= (vla-get-objectname itm) "AcDbAttributeDefinition")
             (= (strcase(vla-get-tagstring itm))(strcase(vla-get-tagstring att))))
      (progn
        (vla-put-layer itm lay)
        (vla-put-layer att lay)
        )
      )
           )
         (vla-update blk)
         )
       )
     )
          )
        )
      (princ)
      )
    (princ "\nType CHATTLAY to run")

  7. #7
    Full Member
    Computer Details
    iTijn's Computer Details
    Operating System:
    XP
    Computer:
    Dell Precision M4300
    Using
    AutoCAD 2010
    Join Date
    Apr 2007
    Posts
    60

    Smile

    Wow! Thank you every body.

    KPBLC: The block definition should remain the same.
    It's just the block reference of which I want to change one attribute to a visible or frozen layer.

    LPSeifert: My excuses for posting the same question on differtent forum groups. I'm not used to forums responding this quickly!!!
    Won't happen again.

    ASMI adn VVA.
    Thank you for the code!
    That's more than I ever wished!

    I will get on with it.!
    Last edited by iTijn; 26th Apr 2007 at 06:09 pm.

  8. #8
    Super Moderator fuccaro's Avatar
    Using
    AutoCAD 2006
    Join Date
    Nov 2002
    Location
    Romania, Marosvasarhely
    Posts
    3,540

    Default

    Quote Originally Posted by iTijn View Post
    LPSeifert: My excuses for posting the same question on differtent forum groups. I'm not used to forums responding this quickly!!!
    Won't happen again.
    That's good! I moved here all the posts about this subject -for your and for our convenience.
    It's nice to be nice, but sometimes is nicer to be evil!.
    Tip: Please do not PM or email me with CAD questions - use the forums, you'll get an answer sooner.

  9. #9
    Full Member
    Computer Details
    iTijn's Computer Details
    Operating System:
    XP
    Computer:
    Dell Precision M4300
    Using
    AutoCAD 2010
    Join Date
    Apr 2007
    Posts
    60

    Default

    The ActiveX code is new to me.
    I have started to read into it (good stuff), but can't find what I need.

    Both of the routines assume that I can select the attribute entity directly with nentsel or nentselp, but in this case I can't because the attribute might be on a frozen layer.

    I assume I have to select the complete block with entsel and than find the nested attribute within that block by attribute name.

    Say curBlk would be the the VLAOBJECT block

    How do I than select a Attribute with the name “CONTYPE” within that block.

    See properties of the block below.

    LOG #<VLA-OBJECT IAcadBlockReference 0a865b34>
    <Application> #<VLA-OBJECT IAcadApplication 00d098b4>
    <Document> #<VLA-OBJECT IAcadDocument 014bbec0>
    <EffectiveName> PINAL
    <Handle> 1D9
    <HasAttributes> :vlax-true
    <HasExtensionDictionary> :vlax-false
    <Hyperlinks> #<VLA-OBJECT IAcadHyperlinks 0a866da4>
    <InsUnits> Millimeters
    <InsUnitsFactor> 1.0
    <InsertionPoint> #<variant 8197 ...>
    <IsDynamicBlock> :vlax-false
    <Layer> PIN_OFF
    <Linetype> ByLayer
    <LinetypeScale> 1.0
    <Lineweight> -1
    <Material> ByLayer
    <Name> PINAL
    <Normal> #<variant 8197 ...>
    <ObjectID> 2130429704
    <ObjectName> AcDbBlockReference
    <OwnerID> 2130414840
    <PlotStyleName> ByLayer

  10. #10
    Super Member ASMI's Avatar
    Using
    AutoCAD 2008
    Join Date
    Nov 2005
    Location
    Oceanus Procellarum, Moon
    Posts
    1,427

    Default

    Registered forum members do not see this ad.

    Hi iTijn.

    Do some actions in command line.
    Select block and get its vla-object:
    Code:
    (setq curBlk(vlax-ename->vla-object(car(entsel))))
    
    Select object: #<VLA-OBJECT IAcadBlockReference 08ad94a4>
    Then get full dump list of properties and methods (in your dump list is only properties because missed T argument in vlax-dump-object function.

    Code:
    Command: (vlax-dump-object curBlk T)
    ; IAcadBlockReference: AutoCAD Block Reference Interface
    ; Property values:
    ;   Application (RO) = #<VLA-OBJECT IAcadApplication 00b9b5e4>
    ;   Document (RO) = #<VLA-OBJECT IAcadDocument 01117f90>
    ;   Handle (RO) = "EC"
    ;   HasAttributes (RO) = -1
    ;   HasExtensionDictionary (RO) = 0
    ;   Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 08adae44>
    ;   InsertionPoint = (0.0 0.0 0.0)
    ;   Layer = "0"
    ;   Linetype = "ByLayer"
    ;   LinetypeScale = 1.0
    ;   Lineweight = -1
    ;   Name = "Test1"
    ;   Normal = (0.0 0.0 1.0)
    ;   ObjectID (RO) = 2130034592
    ;   ObjectName (RO) = "AcDbBlockReference"
    ;   OwnerID (RO) = 2130033912
    ;   PlotStyleName = "ByLayer"
    ;   Rotation = 0.0
    ;   TrueColor = #<VLA-OBJECT IAcadAcCmColor 08adaf10>
    ;   Visible = -1
    ;   XScaleFactor = 1.0
    ;   YScaleFactor = 1.0
    ;   ZScaleFactor = 1.0
    ; Methods supported:
    ;   ArrayPolar (3)
    ;   ArrayRectangular (6)
    ;   Copy ()
    ;   Delete ()
    ;   Explode ()
    ;   GetAttributes ()
    ;   GetBoundingBox (2)
    ;   GetConstantAttributes ()
    ;   GetExtensionDictionary ()
    ;   GetXData (3)
    ;   Highlight (1)
    ;   IntersectWith (2)
    ;   Mirror (2)
    ;   Mirror3D (3)
    ;   Move (2)
    ;   Rotate (2)
    ;   Rotate3D (3)
    ;   ScaleEntity (2)
    ;   SetXData (2)
    ;   TransformBy (1)
    ;   Update ()
    Now you can see GetAttributes and GetConstantAttributes methods. Extract attributes array:

    Code:
    Command: (setq attArr(vla-GetAttributes curBlk))
    #<variant 8201 ...>
    Now you have variant with safearray of attributes inside it. Get list of attributes:

    Code:
    Command: (setq attLst(vlax-safearray->list(vlax-variant-value attArr)))
    (#<VLA-OBJECT IAcadAttributeReference 08ad6f64>)
    Now you have list of attributes (only one attribute in my block) and can use its methods and properties.

    Read this book http://discussion.autodesk.com/servl...sp%20Bible.pdf to get more information about ActiveX.

Similar Threads

  1. Point Block Reference
    By Bridget in forum AutoCAD General
    Replies: 9
    Last Post: 28th Sep 2007, 09:26 pm
  2. how to change a layer color in a block made out several blocks
    By firsrate_caduser in forum AutoCAD General
    Replies: 6
    Last Post: 16th Nov 2006, 06:25 pm
  3. How to change attribute defaults
    By midasxl in forum AutoCAD Drawing Management & Output
    Replies: 1
    Last Post: 13th Nov 2006, 07:11 am
  4. No block attribute entry - only block references
    By broadcastcad in forum AutoCAD Drawing Management & Output
    Replies: 12
    Last Post: 20th Aug 2006, 02:21 am
  5. attribute reference problem
    By j_r_auden in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 9th Feb 2005, 05:00 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts