Results 1 to 10 of 10

Thread: Replacing attribute values via an excel file

  1. #1
    100 Club jgardner.79905's Avatar
    Join Date
    2004-12
    Posts
    153
    Login to Give a bone
    0

    Angry Replacing attribute values via an excel file

    I am trying to see if there is a way to have a lisp routine will find all instances of a particular block and replace the attribute value by looking up the existing attribute value in an excel file and replace it with the new value in the excel file in the next column over. I currently have the routine built that will create a selection set of all instances of this block, run a repeat function to check and replace each attribute value but it's based on a conditions function which means I would have to type about 200 conditions. Can anyone help?

  2. #2
    AUGI Addict
    Join Date
    2008-02
    Posts
    1,141
    Login to Give a bone
    0

    Default Re: Replacing attribute values via an excel file

    I remember reading where someone had posted something like this over at CADTutor.
    http://www.cadtutor.net/forum/index.php

    Search there.

  3. #3
    100 Club jgardner.79905's Avatar
    Join Date
    2004-12
    Posts
    153
    Login to Give a bone
    0

    Default Re: Replacing attribute values via an excel file

    Just to be a little more clear on what I hope can be done...I would like my routine to get the existing attribute value of a particular block, go to a specified excel file and look that value up in a specified column (column "A") and return the value from the next column over (column B) and overright the old attribute value with the value it found from column B. I followed the link in the post above but had no luck. Can this even be done?

  4. #4
    100 Club jgardner.79905's Avatar
    Join Date
    2004-12
    Posts
    153
    Login to Give a bone
    0

    Smile Re: Replacing attribute values via an excel file

    Thanks anyway, I figured it out!

  5. #5
    AUGI Addict
    Join Date
    2008-02
    Posts
    1,141
    Login to Give a bone
    0

    Default Re: Replacing attribute values via an excel file

    Good deal.
    You should share your findings. Might help someone else down the line.

  6. #6
    I could stop if I wanted to CadDog's Avatar
    Join Date
    2005-06
    Location
    So Ca
    Posts
    439
    Login to Give a bone
    0

    Default Re: Replacing attribute values via an excel file

    Quote Originally Posted by alanjt View Post
    Good deal.
    You should share your findings. Might help someone else down the line.
    Ya, like me...

  7. #7
    100 Club jgardner.79905's Avatar
    Join Date
    2004-12
    Posts
    153
    Login to Give a bone
    0

    Thumbs up Re: Replacing attribute values via an excel file

    Sorry everyone I was on vacation. I have attached what I came up with. It could use some cleaning up but it worked like a champ in a crunch. Combine the scripting i have pasted below with Terry Miller's routine "GetExcel". Let me know if you have any questions.

    Special thanks credit to Terry Miller for his "GetExcel" routine.

    Jason


    Script:
    Code:
    (defun c:redeftag (/ Row# OrigCol DestCol ExcellFile ExcellTab OrigList DestList BlkssSelection BlkintCount BlkEnt att attdata attnum NewVal)
      
      (setq Row# "1000"); <-- Set Max Row Value
      (setq OrigCol "A"); <-- Set Key Column Value
      (setq DestCol "B"); <-- Set Destination Col Value
      (setq ExcellFile "P:\\157 West 57th Street - TCG081113\\99 - DWGS\\_Working DWGs\\05_Schedules\\AV\\Master Equipment Schedule\\Master_AV Equipment Schedule.xls"); <-- Referenced Excel file
      (setq ExcellTab "Sheet1"); <-- Specify Tab Name within Workbook
      (setq OrigList (GetExcel ExcellFile ExcellTab (strcat OrigCol Row#))); <-- Set Key Column Max Range 
      (setq DestList (GetExcel ExcellFile ExcellTab (strcat DestCol Row#))); <-- Set Destination Column Max Range 
    
      (setq BlkssSelection (ssget "x" (list (cons 0 "INSERT")(cons 2 "Anno_EqpmTag_AudVid_A1")))); <-- Selection of all desired block
    
      (repeat (setq BlkIntCount (sslength BlkssSelection))
        (setq BlkIntCount (1- BlkIntCount)
    	  BlkEntSelection (ssname BlkssSelection BlkIntCount))
    
        (setq blkent BlkEntSelection
    	flag nil
    	att (entnext blkent)
    	attdata (entget att)
    	attnum (entget (entnext att))
    	)
    
        (if (/= (assoc (cdr (assoc 1 attdata)) Origlist) nil)
          (progn
    	(setq NewVal (Getcell (strcat DestCol (itoa  (+ (vl-position (list (cdr (assoc 1 attdata))) OrigList) 1)))))
    	(entmod (subst (cons 1 NewVal) (assoc 1 attdata) attdata))
    	(command "attsync" "n" "Anno_EqpmTag_AudVid_A1")
    	)
          (princ)
          ); end if
        ); end repeat
      (gc)
      )
    Attached Files Attached Files
    Last edited by RobertB; 2010-05-17 at 06:51 PM. Reason: Added [code] tags

  8. #8
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Default Re: Replacing attribute values via an excel file

    Quote Originally Posted by jgardner.79905 View Post
    Script:
    Code:
    (defun c:redeftag (/ Row# OrigCol DestCol ExcellFile ExcellTab OrigList DestList BlkssSelection BlkintCount BlkEnt att attdata attnum NewVal)
    ...
      (gc)
      )
    BTW, that is not a "script". AutoLISP or Visual LISP code, yes.
    R. Robert Bell
    Design Technology Manager
    Stantec
    Opinions expressed are mine alone and do not reflect the views of Stantec.

  9. #9
    Active Member
    Join Date
    2015-08
    Posts
    59
    Login to Give a bone
    0

    Default Re: Replacing attribute values via an excel file

    Quote Originally Posted by jgardner.79905 View Post
    Sorry everyone I was on vacation. I have attached what I came up with. It could use some cleaning up but it worked like a champ in a crunch. Combine the scripting i have pasted below with Terry Miller's routine "GetExcel". Let me know if you have any questions.

    Special thanks credit to Terry Miller for his "GetExcel" routine.

    Jason


    Script:
    Code:
    (defun c:redeftag (/ Row# OrigCol DestCol ExcellFile ExcellTab OrigList DestList BlkssSelection BlkintCount BlkEnt att attdata attnum NewVal)
      
      (setq Row# "1000"); <-- Set Max Row Value
      (setq OrigCol "A"); <-- Set Key Column Value
      (setq DestCol "B"); <-- Set Destination Col Value
      (setq ExcellFile "P:\\157 West 57th Street - TCG081113\\99 - DWGS\\_Working DWGs\\05_Schedules\\AV\\Master Equipment Schedule\\Master_AV Equipment Schedule.xls"); <-- Referenced Excel file
      (setq ExcellTab "Sheet1"); <-- Specify Tab Name within Workbook
      (setq OrigList (GetExcel ExcellFile ExcellTab (strcat OrigCol Row#))); <-- Set Key Column Max Range 
      (setq DestList (GetExcel ExcellFile ExcellTab (strcat DestCol Row#))); <-- Set Destination Column Max Range 
    
      (setq BlkssSelection (ssget "x" (list (cons 0 "INSERT")(cons 2 "Anno_EqpmTag_AudVid_A1")))); <-- Selection of all desired block
    
      (repeat (setq BlkIntCount (sslength BlkssSelection))
        (setq BlkIntCount (1- BlkIntCount)
    	  BlkEntSelection (ssname BlkssSelection BlkIntCount))
    
        (setq blkent BlkEntSelection
    	flag nil
    	att (entnext blkent)
    	attdata (entget att)
    	attnum (entget (entnext att))
    	)
    
        (if (/= (assoc (cdr (assoc 1 attdata)) Origlist) nil)
          (progn
    	(setq NewVal (Getcell (strcat DestCol (itoa  (+ (vl-position (list (cdr (assoc 1 attdata))) OrigList) 1)))))
    	(entmod (subst (cons 1 NewVal) (assoc 1 attdata) attdata))
    	(command "attsync" "n" "Anno_EqpmTag_AudVid_A1")
    	)
          (princ)
          ); end if
        ); end repeat
      (gc)
      )
    Thanks for info...... works perfect !!!
    Steve

  10. #10
    Member
    Join Date
    2015-08
    Posts
    29
    Login to Give a bone
    0

    Default Re: Replacing attribute values via an excel file

    why this GetExcel lisp routine is not working here in my Autocad 2010 is this can only use in older version?

Similar Threads

  1. Attribute replacing
    By prasanthbalu in forum AutoLISP
    Replies: 23
    Last Post: 2011-07-26, 05:17 PM
  2. 2011: Replacing the PGP File
    By BeKirra in forum AutoCAD General
    Replies: 3
    Last Post: 2010-04-22, 12:09 PM
  3. Replies: 4
    Last Post: 2008-11-13, 05:36 AM
  4. Add Attribute values together
    By ReachAndre in forum AutoLISP
    Replies: 11
    Last Post: 2007-10-31, 03:09 PM
  5. How to go about replacing existing Blocks within a DWG file
    By robert.1.hall72202 in forum AutoCAD General
    Replies: 6
    Last Post: 2007-01-24, 10:08 AM

Posting Permissions

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