+ Reply to Thread
Results 1 to 9 of 9
  1. #1
    Full Member MFish's Avatar
    Computer Details
    MFish's Computer Details
    Operating System:
    Windows XP
    Computer:
    Dell
    RAM:
    4GB
    Monitor:
    19" Dell
    Using
    Electrical 2010
    Join Date
    Feb 2008
    Location
    Wichita, KS
    Posts
    38

    Default Working with Schematic Reports...

    Registered forum members do not see this ad.

    Hello everyone,

    I am working with a drawing list report on 2008 Electrical, and I have some to very little knowledge of how to write my own LISP routine.
    I am in need of a LISP routine that can basically merge or concatenate two columns. Each of these columns have multiple rows that I need to be kept as rows. But I need the columns to be merged together, and join the information from both columns together as well. Now, of course I have no idea if this is really possible... But any information that I can get would be greatly appreciated. Thanks!

  2. #2
    Super Member fixo's Avatar
    Computer Details
    fixo's Computer Details
    Operating System:
    Windows 7
    Motherboard:
    E7500
    CPU:
    Intel(R)Core(TM)2 DUO CPU 2.93HGz
    RAM:
    4098 Gb
    Graphics:
    1024 Gb
    Using
    AutoCAD 2009
    Join Date
    Jul 2005
    Location
    Thanks God, I'm far enough from Hitleropa
    Posts
    1,697

    Default

    Try this one

    Code:
    (defun C:CL (/  data en i ip mark output ss tmp txt)
    (alert "Select two columns with any method")  
    (setq ss (ssget (list (cons 0 "TEXT"))) i -1)
    (repeat (sslength ss)
      (setq en (ssname ss (setq i (1+ i)))
    	ip (cdr (assoc 10 (entget en)))
    	txt (cdr (assoc 1 (entget en)))
    	tmp (cons txt ip)
    	data (cons tmp data)))
    
    (setq data
    (vl-sort data
    (function (lambda (a b)
    (<= (car (cdr a))(car (cdr b)))))))
      
      (while data
        (setq mark (car data))
        (setq tmp (vl-remove-if-not (function (lambda(x)
    					(equal (car (cdr x))(car (cdr mark)) 0.01)))
    		data))
        (setq tmp (vl-sort tmp (function (lambda (a b)
    				      (> (cadr (cdr a))(cadr (cdr b)))))))
        (setq output (append output(list (mapcar 'car tmp)) ))
        (setq data (vl-remove-if (function (lambda(x)
    					(equal (car (cdr x))(car (cdr mark)) 0.01)))
    		data)))
    
    (setq output (mapcar 'list (car output) (cadr output)))
      (alert "Do whatever you need with this list")
    (princ)
      )
    (prompt "\n====================================================\n")
    (prompt "\n\t>>>\tType CL to execute ... \t>>>\n")
    (prompt "\n====================================================\n")
    (princ)
    ~'J'~
    The soul is healed by being with children. - Fyodor Dostoyevsky, novelist (1821-1881)

  3. #3
    Full Member MFish's Avatar
    Computer Details
    MFish's Computer Details
    Operating System:
    Windows XP
    Computer:
    Dell
    RAM:
    4GB
    Monitor:
    19" Dell
    Using
    Electrical 2010
    Join Date
    Feb 2008
    Location
    Wichita, KS
    Posts
    38

    Default

    The routine works great! But unfortunately not on this specific table that I have. And the only reason or explanation I have is this... When I run the drawing list report and put it on my drawing, it comes in as a single entity. So I guess maybe the problem is that I can't select any individual part of the table. The routine that you posted states that I can use any method to select the two columns, so just to see what happened I tried selecting the whole table with a window and just by clicking on it and it acted like there was nothing there. It just kept saying zero objects selected. Now I did try it on a regular everyday table and it worked just fine, so maybe I just need to stick with those

    I do appreciate your help and any time that you put into this, and thank you!

  4. #4
    Super Member fixo's Avatar
    Computer Details
    fixo's Computer Details
    Operating System:
    Windows 7
    Motherboard:
    E7500
    CPU:
    Intel(R)Core(TM)2 DUO CPU 2.93HGz
    RAM:
    4098 Gb
    Graphics:
    1024 Gb
    Using
    AutoCAD 2009
    Join Date
    Jul 2005
    Location
    Thanks God, I'm far enough from Hitleropa
    Posts
    1,697

    Default

    Upload here this piece of your working
    drawing to work with it directly,
    in this case I'll help I hope
    Ah, and attach there some explanation
    about your task

    ~'J'~
    The soul is healed by being with children. - Fyodor Dostoyevsky, novelist (1821-1881)

  5. #5
    Full Member MFish's Avatar
    Computer Details
    MFish's Computer Details
    Operating System:
    Windows XP
    Computer:
    Dell
    RAM:
    4GB
    Monitor:
    19" Dell
    Using
    Electrical 2010
    Join Date
    Feb 2008
    Location
    Wichita, KS
    Posts
    38

    Default

    In the table, there are three columns. Sheet No. Drawing Title and Dwgtitle2. My goal is to take the information in dwgtitle2 and merge it with Drawing Title. As you can see from the attachment, the biggest problem I have is that when I run the report it wants to split all the attributes into seperate columns. So when it does that it seperates my drawing descriptions.
    Attached Files

  6. #6
    Super Member fixo's Avatar
    Computer Details
    fixo's Computer Details
    Operating System:
    Windows 7
    Motherboard:
    E7500
    CPU:
    Intel(R)Core(TM)2 DUO CPU 2.93HGz
    RAM:
    4098 Gb
    Graphics:
    1024 Gb
    Using
    AutoCAD 2009
    Join Date
    Jul 2005
    Location
    Thanks God, I'm far enough from Hitleropa
    Posts
    1,697

    Default

    Try this instead
    Just select table you need
    it will concatenate 2nd with 3rd column

    Code:
    ;;MT.lsp
    ;;load ActiveX stuffs
    (vl-load-com)
    ;;local defun
    (defun get-table-contents (/ atable col cols data datum row rows  sset
            start  tmp)
      (prompt "\n\t>>>\tSelect table\t>>>\n")
      (setq sset (ssget "_:S" '((0 . "ACAD_TABLE"))))
      (setq  atable (vlax-ename->vla-object (ssname sset 0))
      cols   (vla-get-columns atable)
      rows   (vla-get-rows atable)
      start  rows
      )
      (if (eq :vlax-true (vla-get-titlesuppressed atable))
        (setq rows (1- rows))
      )
      (if (eq :vlax-true (vla-get-headersuppressed atable))
        (setq rows (1- rows))
      )
      (setq row (- start rows))
      (repeat rows
        (setq col 0)
        (repeat cols
          (setq datum (vla-gettext atable row col))
          (setq tmp (cons datum tmp))
          (setq col (1+ col))
        )
        (setq data (cons (reverse tmp) data)
        tmp  nil
        row  (1+ row)
        )
      )
      (reverse data)
    )
    
    ;; main part:
    (defun C:MC ();merge columns
    (setq data_list (get-table-contents))
    ;; result list you need:
    (setq merged
    (vl-remove-if (function not)
    (mapcar (function (lambda (x)
    		    (if (not (eq "" (cadr x)))
    			 (strcat (cadr x) (chr 32) (caddr x)))))
    	data_list)
      )
          )
    (alert (strcat "Concatenated list of strings:\n\n"
    (apply 'strcat
    (mapcar (function (lambda(x)(strcat x "\n")))  merged)))
    		   )
    (princ)
      )
    (prompt "\n====================================================\n")
    (prompt "\n\t>>>\tType MC to merge columns ... \t>>>\n")
    (prompt "\n====================================================\n")
    (princ)
    ~'J'~
    The soul is healed by being with children. - Fyodor Dostoyevsky, novelist (1821-1881)

  7. #7
    Senior Member
    Using
    AutoCAD 2008
    Join Date
    Nov 2005
    Location
    Bulgaria, Sofia
    Posts
    237

    Default

    Hi MFish,

    If your desire is to merge second and third columns of the table in your drawing may be the following macro might be useful for you. When you run it from the VBA Editor it lets you to select a table, then merges the columns

    Code:
    Sub MergeColumnsOfTable()
        On Error Resume Next
        Dim oEnt As AcadEntity
        Dim varPick As Variant
        ThisDrawing.Utility.GetEntity oEnt, varPick, vbCr & "Select a table: "
        If Err Then
            Err.Clear
            MsgBox "Nothing selected"
            Exit Sub
        End If
        
        MsgBox oEnt.ObjectName
        If oEnt.ObjectName <> "AcDbTable" Then
            MsgBox "The object selected is not a table!"
            Exit Sub
        End If
        
        Dim MyTable As AcadTable
        Set MyTable = oEnt
        
        If MyTable.Columns < 2 Then
            MsgBox "This table has less than 3 columns and cannot be processed!"
            Exit Sub
        End If
        
        Dim i As Integer
        For i = 1 To MyTable.Rows
            MyTable.SetText i, 1, MyTable.GetText(i, 1) & " " & MyTable.GetText(i, 2)
        Next
        MyTable.DeleteColumns 2, 1
    End Sub

  8. #8
    Full Member MFish's Avatar
    Computer Details
    MFish's Computer Details
    Operating System:
    Windows XP
    Computer:
    Dell
    RAM:
    4GB
    Monitor:
    19" Dell
    Using
    Electrical 2010
    Join Date
    Feb 2008
    Location
    Wichita, KS
    Posts
    38

    Default

    I just wanted to take a quick moment and thank the both of you for helping me! The routine works perfectly and I could have never done it without your help

    Sorry its been so long, I got put onto another project before I could have a chance to try this. But I did try it today, and it saves so much time! So... "Thank you again"

  9. #9
    Full Member MFish's Avatar
    Computer Details
    MFish's Computer Details
    Operating System:
    Windows XP
    Computer:
    Dell
    RAM:
    4GB
    Monitor:
    19" Dell
    Using
    Electrical 2010
    Join Date
    Feb 2008
    Location
    Wichita, KS
    Posts
    38

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by Joro-- View Post
    Hi MFish,

    If your desire is to merge second and third columns of the table in your drawing may be the following macro might be useful for you. When you run it from the VBA Editor it lets you to select a table, then merges the columns

    Code:
    Sub MergeColumnsOfTable()
        On Error Resume Next
        Dim oEnt As AcadEntity
        Dim varPick As Variant
        ThisDrawing.Utility.GetEntity oEnt, varPick, vbCr & "Select a table: "
        If Err Then
            Err.Clear
            MsgBox "Nothing selected"
            Exit Sub
        End If
     
        MsgBox oEnt.ObjectName
        If oEnt.ObjectName <> "AcDbTable" Then
            MsgBox "The object selected is not a table!"
            Exit Sub
        End If
     
        Dim MyTable As AcadTable
        Set MyTable = oEnt
     
        If MyTable.Columns < 2 Then
            MsgBox "This table has less than 3 columns and cannot be processed!"
            Exit Sub
        End If
     
        Dim i As Integer
        For i = 1 To MyTable.Rows
            MyTable.SetText i, 1, MyTable.GetText(i, 1) & " " & MyTable.GetText(i, 2)
        Next
        MyTable.DeleteColumns 2, 1
    End Sub

    As I said before I do appreciate and love the great response and help I received before... You guys are awesome!

    I do have another issue that I am working with now though. I am using the macro that I have quoted above, and it works. Now what I am wondering is if it is possible to have it insert a specific number of rows into the table in the same macro. So that it does the merging, then maybe asks where and how many rows I would like to have inserted.

    Thanks in advance for any help any of you provide!

Similar Threads

  1. Working with 3D
    By Rhayes in forum AutoCAD Drawing Management & Output
    Replies: 2
    Last Post: 23rd Aug 2007, 05:14 pm
  2. It's working and thank you
    By TroutKing in forum AutoLISP, Visual LISP & DCL
    Replies: 0
    Last Post: 30th May 2007, 03:43 pm
  3. 85% Do Not Enter an Email in Their Error Reports
    By Between the Lines in forum AutoCAD RSS Feeds
    Replies: 0
    Last Post: 5th Sep 2006, 01:43 pm
  4. Why isn't this working?
    By Baçon in forum AutoLISP, Visual LISP & DCL
    Replies: 3
    Last Post: 18th May 2005, 10:17 pm
  5. Printing CAD DWF into Access reports
    By Vinny1974 in forum AutoCAD Drawing Management & Output
    Replies: 1
    Last Post: 21st May 2004, 11:47 am

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