See the top rated post in this thread. Click here

Results 1 to 7 of 7

Thread: Attach xdata to 3DSolid in block

  1. #1
    Member
    Join Date
    2016-05
    Posts
    5
    Login to Give a bone
    0

    Default Attach xdata to 3DSolid in block

    I'm attempting to write a routine that will open a block in a drawing and attach some xdata to the 3DSolid that is in the block, save and close the block and continue until this is done for all blocks in the drawing. Each block in the drawing only contains one 3DSolid. Thanks in advance for your help. I'm an AutoLISP greenhorn so adding comments in any code would be greatly appreciated.

  2. #2
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Chelan WA
    Posts
    1,056
    Login to Give a bone
    0

    Default Re: Attach xdata to 3DSolid in block

    What are you adding to the 3dsolid and for what reason. Is it the same for all solids? It isn't hard to do but I need more information.

    P=
    AutomateCAD

  3. #3
    Member
    Join Date
    2016-05
    Posts
    5
    Login to Give a bone
    0

    Default Re: Attach xdata to 3DSolid in block

    Quote Originally Posted by peter View Post
    What are you adding to the 3dsolid and for what reason. Is it the same for all solids? It isn't hard to do but I need more information.

    P=
    Hi Peter. I'm reading in data from a csv (using Lee Mac's read csv) into a list of lists. The csv has the following headers: Name, Type, Stock, Material, Grade. The Name is the name of the block in the drawing so I'm using (setq blk (car line)) then making a call to (command "_.bedit" blk). I'm planning to also use 'blk' as an xdata string for the Name. I am then attempting to select the solid in the block with (setq ss1 (ssget "_A" '((0 . "3DSOLID")))). The part that I'm really tripping up on is iterating over/looping through the lists and attaching the xdata. I'm familiar with C++ loop structures so my thinking is that I could nest for loops to do this on the inner and outer lists but I just don't quite know how to do this in AutoLISP. I hope I'm not too far off track here.

  4. #4
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Chelan WA
    Posts
    1,056
    Login to Give a bone
    1

    Default Re: Attach xdata to 3DSolid in block

    Here is piece of sample code.

    It iterates through the block collection and figures out the effectivename (even of anonymous blocks) and then iterates through the item collection and finds the solids.

    You just need to search the list of sublists, find the data and add it as xdata to the object.

    You could use ldata too.

    Code:
    (Defun C:SolidXdata (/ objBlockDefinition objItem)
     (vl-load-com)
     (vlax-for objBlockDefinition (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
      (setq strBlockName (BlockDefinitionEffectiveName objBlockDefinition))
      (print strBlockName)
      (vlax-for objItem objBlockDefinition
       (if (wcmatch (vla-get-objectname objItem) "AcDb3dSolid")
        (print objItem)
       ) 
      )
     )
    )
    
    ; Function to get the effectivename of a block definition.
    
    (defun BlockDefinitionEffectiveName (objBlockDefinition / dprAssoc lstEntity objBlock strBlockName)
    
     (setq strBlockName (vla-get-name objBlockDefinition))
     (and (= (substr strBlockName 1 1) "*")
          (setq lstEntity (entget (vlax-vla-object->ename objBlockDefinition)))
          (setq dprAssoc (assoc 331 lstEntity))
          (setq objBlock (vlax-ename->vla-object (cdr dprAssoc)))
          (setq strBlockName (vla-get-effectivename objBlock))              
     )
     strBlockName
    )
    AutomateCAD

  5. #5
    Member
    Join Date
    2016-05
    Posts
    5
    Login to Give a bone
    0

    Default Re: Attach xdata to 3DSolid in block

    I'm having trouble creating a valid list that can be attached as xdata to the entity. Here is the list that I'm attempting to create:

    Code:
                   (setq e1 '((-3 ("MYXDATA"
    			 (1000 . "Part")
    		  	 (cons 1000 strBlk)
    		   	 (1000 . "Stock")
                             (cons 1000 strStock)
    		         (1000 . "Stock Type")
                             (cons 1000 strStkType)
    		 	 (1000 . "Material and Grade")
                             (cons 1000 strMatl)
                                               ))))
    I can't figure out how to have the variable evaluated and have the result added to the list. If I comment out the 4 lines that contain variables, it works fine. Thanks in advance for any help provided.

  6. #6
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    8,517
    Login to Give a bone
    1

    Default Re: Attach xdata to 3DSolid in block

    Replace '( with (list.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  7. #7
    Member
    Join Date
    2016-05
    Posts
    5
    Login to Give a bone
    0

    Default Re: Attach xdata to 3DSolid in block

    Thanks Opie. This did the trick. I changed '( to (list and then wrapped the entire collection in another (list ... ) and it worked like a charm. Now I need to go implement peter's suggestion around this instead of opening the block editor to attach the data. Thanks guys!

Similar Threads

  1. Select & entget object information in XREF and block-in-block with Lisp
    By Wish List System in forum AutoCAD Wish List
    Replies: 0
    Last Post: 2012-11-14, 09:11 AM
  2. Select dynamic block and change to a different block
    By john.237249 in forum AutoLISP
    Replies: 0
    Last Post: 2012-03-05, 08:09 PM
  3. Plot without edge lines in a 3dsolid?
    By navisworks in forum AutoCAD 3D (2007 and above)
    Replies: 5
    Last Post: 2009-06-09, 12:14 AM
  4. Get a LISP to Select a Face on a 3DSolid?
    By tdswanson in forum AutoLISP
    Replies: 1
    Last Post: 2009-03-26, 10:23 PM
  5. how to get cross section for 3dSolid?
    By gkhokhorin in forum ARX
    Replies: 0
    Last Post: 2009-02-05, 10:56 PM

Posting Permissions

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