Jump to content

Text concatenate LISP editing


romparkin

Recommended Posts

Hello,

I use a LIPS found here (https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/text-concatenate/m-p/5819272/highlight/true#M335121)

to merge / concatenate texts from a plan, then l copy paste this in Excel to make tables with data (coordinates, distances, etc...).

The LIPS works, but in order to speed up the process , I want to add after every 4-th text I select a different separator , for example "/" instead of "," 

So after selected texts nr. 1,2,3,5,6,7,9,10,11,13,14,.... separator is "," 

but after selected texts nr. 4,8,12,16,... to have "/" as separator.

 

Is this a complicated thing to achieve ?

I'm not very good with LISP , and not sure where I can start.

Need to mention that I work with Intellicad, so Visual Lisp won't work.

 

Here is the LISP I use:

 

(defun c:conc (/ a ans b c d e f g h j)
   (graphscr)
   (command ".redraw") (command)
(initget "Yes No")
(if (= "Yes" (getkword "\nRetain Append Text? [Y/N] <N>: "))
(setq j 0); Yes
(setq j 1); No
)
   (prompt "\nSelect Text to Remain->")
   (setq a (entsel))
   (while (setq b (entsel "\nSelect Text to Append -> "))
     (setq c (entget (car a))
           d (entget (car b))
           e (cdr (assoc 1 c))    ;get 1st text string
           f (cdr (assoc 1 d))    ;get 2nd text string
           g (strcat e "," f)
	   h (subst (cons 1 g) (assoc 1 c) c)
     )
     (entmod h)                    ;update 1st string
     
(if (eq j 1)
     (entdel (car b))
  )
     (princ)
   )
)

 

 

Thanks

Romeo

Link to comment
Share on other sites

  • Replies 31
  • Created
  • Last Reply

Top Posters In This Topic

  • romparkin

    14

  • BIGAL

    13

  • Steven P

    2

  • exceed

    2

Top Posters In This Topic

Posted Images

Try changing this:

 

   (while (setq b (entsel "\nSelect Text to Append -> "))
     (setq c (entget (car a))
           d (entget (car b))
           e (cdr (assoc 1 c))    ;get 1st text string
           f (cdr (assoc 1 d))    ;get 2nd text string
           g (strcat e "," f)
	   h (subst (cons 1 g) (assoc 1 c) c)
     )
     (entmod h)                    ;update 1st string

 

to this

 

   (setq acount 0)
   (while (setq b (entsel "\nSelect Text to Append -> "))
     (setq acount (+ acount 1)
     (if (= 4 acount)
       (progn
         (setq acount 0)
         (setq seperator "/")
       )
       (setq seperator ",")
    )

     (setq c (entget (car a))
           d (entget (car b))
           e (cdr (assoc 1 c))    ;get 1st text string
           f (cdr (assoc 1 d))    ;get 2nd text string
           g (strcat e seperator f)
	   h (subst (cons 1 g) (assoc 1 c) c)
     )
     (entmod h)                    ;update 1st string

 

Link to comment
Share on other sites

Untested, but something like this should work as well:

  (setq n 0)
  (prompt "\nSelect Text to Remain->")
  (setq a (entsel))
  (while (setq b (entsel "\nSelect Text to Append -> "))
    (setq c (entget (car a))
	  d (entget (car b))
	  e (cdr (assoc 1 c))		;get 1st text string
	  f (cdr (assoc 1 d))		;get 2nd text string
	  g (strcat e
		    (if	(= 0 (rem (setq n (1+ n)) 4))
		      "/"
		      ","
		    )
		    f
	    )
	  h (subst (cons 1 g) (assoc 1 c) c)
    )
    (entmod h)				;update 1st string
    (if	(eq j 1)
      (entdel (car b))
    )
    (princ)
  )

 

Link to comment
Share on other sites

It may be easier to take '(1 2 3 4 5 6 7 8 9) and write direct to excel if a column answer is required just read every 4 from list. Note need a last step for < 4

 

(while (/ num 4) is > 3.9999999 where num starts as length of a list. 

 

Going fishing now so maybe later.

 

Post a excel of result and a dwg. 

Link to comment
Share on other sites

Thank you guys, both solutions tested and worked fine.

I have one question, is it possible to see the number of merged  text elements  in the command bar?

I see the merged text on the first 3,4 text selection, but when I move on the plan I'm not seeing the merged text until I'm finished and I'm panning back to the place my text is, so if I miss a text I have to redo the process.

If I can see in command bar then number of texts I clicked, I know if I made a mistake or not.

Or maybe to see in command bar the content of the last selected text ...

 

Right now in Command Bar I see this:

Select Text to Remain->
Select Text to Append ->
Select Text to Append ->
Select Text to Append ->

.....

 

Would be great to see see this:

Select Text to Remain->
Select Text to Append (2) ->
Select Text to Append  (3)->
Select Text to Append (4)->

.....

Thank you again for the help.

Romeo

Edited by romparkin
Link to comment
Share on other sites

Numbering the text should be easy enough, change the question below, noting that you can use (strcat .....) to join texts within an entsel

 

(while (setq b (entsel "\nSelect Text to Append -> "))

 

in my example to

(while (setq b (entsel (strcat "\nSelect Text to Append (" acount ") -> ")))

 

and in ronjonps (note here the first text to pick will say "Select Text to Append (nil)" instead of 0)

 

(while (setq b (entsel (strcat "\nSelect Text to Append (" n ") -> ")))

 

To see the last text you select then use (princ ..... ) and whatever you want in the command line for example just before (entmod h) put this in:

 

(princ f)

 

Link to comment
Share on other sites

9 minutes ago, Steven P said:

To see the last text you select then use (princ ..... ) and whatever you want in the command line for example just before (entmod h) put this in:

 

(princ f)

 

 

Thanks a lot Steven

the (princ f) is giving me exactly what I need, to see exactly where I am with text merging.

Romeo

Link to comment
Share on other sites

6 hours ago, BIGAL said:

Again Post a excel of result and a dwg. 

 

HI BIGAL

sorry for late reply

 

Here is an example road axis with some text data I need to copy to Calc/excel/Google sheets , then in Calc I make some automatic formatting with formulas.

The lisp file is helping me get the info in one long text, that I will Special paste in Calc/Google sheets a,d the separators will place data in cells and rows.

It's already working fine, and speeds up the process. I used to copy each text element individually and paste, but now I select the texts in a specific order, then paste all, and it saves me lot of time.

It's useful for larger projects, but still I'm working only 1KM a time , as I need to check if all elements are copied correctly.

 

Thanks for the support

Romeo

Demo-cadtutor.dwg data table from progecad.xls

Link to comment
Share on other sites

This can all be done in possibly one go. I think you making life hard for your self.

 

Set start chainage of pline KM 46+000.0178 probably KM 46+000

Select points that are in the dwg as text X= 540298.90 Y= 537753.84 where does this text come from ? Was it originally points ? How is it determined ?

Once you have the points can get the offset 6.87 getclosestpointto 

Write a csv line by line for excel or direct to excel.

All done 

 

The XY text appears to be the insert point of the text but see question above.

 

There are Chainage.lsp programs out there so have something to look at for ideas. Need a get offset points to pline that will exist.

 

If you can answer how the dwg was made I am sure we can automate steps you are taking now to like a pick and 1 selection. Pretty standard CIVIL type request.

Edited by BIGAL
Link to comment
Share on other sites

On 2/20/2022 at 7:19 AM, BIGAL said:

This can all be done in possibly one go. I think you making life hard for your self.

 

Set start chainage of pline KM 46+000.0178 probably KM 46+000

Select points that are in the dwg as text X= 540298.90 Y= 537753.84 where does this text come from ? Was it originally points ? How is it determined ?

Once you have the points can get the offset 6.87 getclosestpointto 

Write a csv line by line for excel or direct to excel.

All done 

 

The XY text appears to be the insert point of the text but see question above.

 

There are Chainage.lsp programs out there so have something to look at for ideas. Need a get offset points to pline that will exist.

 

If you can answer how the dwg was made I am sure we can automate steps you are taking now to like a pick and 1 selection. Pretty standard CIVIL type request.

 

Hi BIGAL

I know I do extra steps, but creating one lisp to include all the steps would be a work to complex for me.

 

Here are the steps I'm using:

1- I use a Chainage lisp , to automatically mark each KM on my road axis (http://www.gilesdarling.me.uk/lisproutines.shtml

2 - On plan I have some poles that will be used and sometimes I will place new poles , then II add points manually to each pole ,and using another lisp I quickly generate text with X,Y coordinates

3. Using a third lips I draw perpendicular lines, from points to the polyline

4. Now using chainage lisp from step one, I mark each perpendicular line to polyline and get chainage data for the poles

5. Using another lisp I fix chainage data from 46.368.335 to 46+368.33

6. Then I uses a function in Intellicad, that adds a Prefix to all chainage text : Km 46+368.33

7. Another lisp is used to measure and add to my plan the distance of each perpendicular line (from point to polyline) as Mtext : Distance 6.35 m , Distance 4.32 m, etc....

And I explode once this text are done so I get the "6.35 m" as a separate text from "Distance"

8. Now I add next to each point a text ,  if is on the left or right of polyline , I made a simple Lisp where I I select Left and it places the text Left, or Right and places text Right

9. And Finally Using the Concatenate lisp I merge the "KM 46+322.56" with "Left" with "6.35" with "X=52325.22 Y=44525.36" for each Pole on 1 km, I Get a text like:

 

Km 46+015.00,Dreapta,6.09 m,X= 540273.44 Y= 537696.42/

Km 46+046.55,Dreapta,6.32 m,X= 540286.35 Y= 537725.21/

Km 46+077.67,Stanga,6.87 m,X= 540298.90 Y= 537753.84/

Km 46+109.44,Stanga,6.40 m,X= 540310.46 Y= 537783.52/

Km 46+135.22,Dreapta,6.30 m,X= 540319.74 Y= 537807.67/

Km 46+174.90,Dreapta,6.29 m,X= 540334.02 Y= 537844.52/

 

And this text goes to LibreOffice Calc,  where "," and "/" are set as separators and the text are placed in individual cells.

In Calc I add a Column in between "6.09 m" and "X Y" , with a formula that IF the distance is > 6.5 , add a text, and if is lower (<) add a different text

And I add another Column before "X,Y" with text "Existing Pole" or "New Pole 01" where 01 is always different, depending how many new poles I add

 

You can see attached the final table in a .doc file.

 

I'm not a developer, I have some experience with Javascript, but LISP seems hard for me to learn, I also Investigated a bit VBA but got stuck quickly.

So I use all this small Lisp files, and I work faster if comparing to the first projects where I basically copied each text one by one and paste it into word doc file for each cell.

Also I used to measure manually the chainages and distances for perpendicular lines, etc..

 

Regards

Romeo

 

 

 

example table.jpg

Edited by romparkin
Link to comment
Share on other sites

Ok providing the poles are on say a layer its all easy, there is these 2 functions that do the hard work.

 

(vlax-curve-getclosestpointto obj pt) this will work out the point on the pline square of your point. So get distance offset.

 

(vlax-curve-getdistatpoint obj pt) this will give you the distance from the pline start point, so add to start chainage.

 

Ok will create poles at text point in sample dwg and do something for you may be a couple of days

 

Link to comment
Share on other sites

Ok this is a start if each power pole is on layer "power poles" then they will be found. You select the points, then the pline, enter start chainage, I expect they will be a block so need names.

 

This is a simple result chainage, offset and XYZ of power pole point. Can add say layer or blockname. 

 

((46352.6197094854 7.94206387971368 (540422.173822538 537997.380907406 0.0))

(46399.9335452063 6.22681330774058 (540448.012596028 538033.964168227 0.0))

(46434.1549164408 6.52507594756663 (540474.929418994 538054.400748503 0.0))

(46475.829951876 6.8359254882615 (540508.061803933 538077.949478698 0.0))

(46977.4417785467 9.33341049935792 (540809.708407411 538438.500021386 0.0))

(46942.1797262236 5.2260128611048 (540788.17640741 538409.531021385 0.0))

 

So next question is what do you really want ?

label all values like sample

create a table

export to excel 

 

Need a real dwg so can see power poles.

 

; https://www.cadtutor.net/forum/topic/74514-text-concatenate-lisp-editing/

(defun c:test ( / ss ent obj pt ptpl ch off lst)
(setq ss (ssget (list (cons 0 "point")(cons 8 "Power poles"))))

(setq ent (car  (entsel "Pick obj")))
(setq obj (vlax-ename->vla-object ent))

(setq stch (getreal "\nPlease enter start chainage "))

(setq lst '())

(repeat (setq x (sslength ss))
  (setq pt (cdr (assoc 10 (entget (ssname ss (setq x (1- x)))))))
  (setq ptpl (vlax-curve-getclosestpointto obj pt))
  (setq ch (+ stch (vlax-curve-getdistatpoint obj ptpl)))
  (setq off (distance ptpl pt))
  (setq lst (cons (list ch off pt) lst))
)

(setq lst (vl-sort lst '(lambda (x y) (< (car x)(car y)))))

(princ)
)

 

 

 

 

 

 

Link to comment
Share on other sites

(defun c:test ( / ss ent obj pt ptpl ch off lst)

(vl-load-com)

(setq ss (ssget (list (cons 0 "point")(cons 8 "Power poles"))))

(setq ent (car  (entsel "Pick obj")))
(setq obj (vlax-ename->vla-object ent))

(setq stch (getreal "\nPlease enter start chainage "))

(setq lst '())

(repeat (setq x (sslength ss))
  (setq pt (cdr (assoc 10 (entget (ssname ss (setq x (1- x)))))))
  (setq ptpl (vlax-curve-getclosestpointto obj pt))
  (setq ch (+ stch (vlax-curve-getdistatpoint obj ptpl)))
  (setq off (distance ptpl pt))
  (setq lst (cons (list ch off pt) lst))
)

(setq lst (vl-sort lst '(lambda (x y) (< (car x)(car y)))))

(princ)
)

 

 

Hi BIGAL

 

I tested the lisp, I use Progecad 2021 (Intellicad 9.2a), and wasn't working so I added this line (vl-load-com)

And its working until I add chainage:

- I select one point on "Power poles" layer, then select similar to get all the points on the layer

- next it type command TEST

- Now message say "Pick obj" , and I select the polyline

- New message say "enter start chainage" , I add for example 42 , or 42000

- error message say "bad type argument"

 

 

I attached the dwg, there are points on "Power poles" layer, and Blocks on the "0" later

 

The data must be displayed on a plan, but I also need it on a doc, that why I'm copying text to LibreOffice Calc sheets, to make some further editing adding some extra columns

 

Regards

Romeo

 

 

demo-poles-road-axis.dwg

Link to comment
Share on other sites

(defun c:conc2 ( / ss ssl ssindex textlist textstacklist ent textcontents textlist textlayer pt text2write )
;;-------------------=={ UnFormat String }==------------------;;
;;                                                            ;;
;;  Returns a string with all MText formatting codes removed. ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright ⓒ 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  str - String to Process                                   ;;
;;  mtx - MText Flag (T if string is for use in MText)        ;;
;;------------------------------------------------------------;;
;;  Returns:  String with formatting codes removed            ;;
;;------------------------------------------------------------;;

(defun LM:UnFormat ( str mtx / _replace rx )

    (defun _replace ( new old str )
        (vlax-put-property rx 'pattern old)
        (vlax-invoke rx 'replace str new)
    )
    (if (setq rx (vlax-get-or-create-object "VBScript.RegExp"))
        (progn
            (setq str
                (vl-catch-all-apply
                    (function
                        (lambda ( )
                            (vlax-put-property rx 'global     actrue)
                            (vlax-put-property rx 'multiline  actrue)
                            (vlax-put-property rx 'ignorecase acfalse) 
                            (foreach pair
                               '(
                                    ("\032"    . "\\\\\\\\")
                                    (" "       . "\\\\P|\\n|\\t")
                                    ("$1"      . "\\\\(\\\\[ACcFfHLlOopQTW])|\\\\[ACcFfHLlOopQTW][^\\\\;]*;|\\\\[ACcFfHLlOopQTW]")
                                    ("$1$2/$3" . "([^\\\\])\\\\S([^;]*)[/#\\^]([^;]*);")
                                    ("$1$2"    . "\\\\(\\\\S)|[\\\\](})|}")
                                    ("$1"      . "[\\\\]({)|{")
                                )
                                (setq str (_replace (car pair) (cdr pair) str))
                            )
                            (if mtx
                                (_replace "\\\\" "\032" (_replace "\\$1$2$3" "(\\\\[ACcFfHLlOoPpQSTW])|({)|(})" str))
                                (_replace "\\"   "\032" str)
                            )
                        )
                    )
                )
            )
            (vlax-release-object rx)
            (if (null (vl-catch-all-error-p str))
                str
            )
        )
    )
)
(vl-load-com)



 (setq ss (ssget '((0 . "*TEXT"))))
 (setq pt (getpoint "\n pick point to place result text"))
 (setq ssl (sslength ss))
 (if (= ssl 4)
     (progn ;(princ "\n yes 4 texts.")
        (setq ssindex 0)
        (setq textlist nil)
        (setq textstacklist nil)
        (repeat ssl
          (setq ent (entget (ssname ss ssindex)))
          (setq textcontents (LM:UnFormat (cdr (assoc 1 ent)) nil))
          (setq textlayer (cdr (assoc 8 ent)))
          (setq textsize (cdr (assoc 40 ent)))
          (setq textlist (list textlayer textcontents))
          (setq textstacklist (cons textlist textstacklist))
          (setq ssindex (+ ssindex 1))
        )

        ;sort by layer
        (setq textstacklist (vl-sort textstacklist
                                     (function
                                         (lambda (x1 x2)(< (car x1) (car x2)))
                                     )
                                  )
        )
        ;(princ textstacklist)               

        (setq text2write "")
        (setq text2write (strcat (vl-princ-to-string (cadr (nth 2 textstacklist))) "," (vl-princ-to-string (cadr (nth 0 textstacklist))) "," (vl-princ-to-string (cadr (nth 1 textstacklist))) "," (vl-princ-to-string (cadr (nth 3 textstacklist))) "/"))
        (princ text2write)
;|
      (entmake (list
                 '(0 . "MTEXT")
                 '(100 . "AcDbEntity")
                 '(100 . "AcDbMText")
                 (cons 10 pt)
                 (cons 1 text2write)
               )
      )

|;
        (entmake (list (cons 0 "TEXT")
                          (cons 1 text2write)
		  (cons 8 (car (nth 0 textstacklist)))
		  (cons 10 pt)
  		  (cons 40 textsize)
		  (cons 50 0)
	         )
         )

     )
     (progn (princ "\n no 4 texts.") (c:conc2))
 )

(princ)
)

 

Sorry among the masters,

this is a lisp that just merges 4 texts.

 

If you always have the same layer names order, will help.

If you select a number other than 4, it exits.

 

command is conc2

2022-02-22 18;07;58.PNG

 

 

and then use this TEXTEXPORT 

for export to csv excel file

 

 

 

Of course, if you sort those texts at the stage of making them, you will be able to print the list at once.

Edited by exceed
Link to comment
Share on other sites

3 hours ago, exceed said:
(defun c:conc2 ( / ss ssl ssindex textlist textstacklist ent textcontents textlist textlayer pt text2write )
;;-------------------=={ UnFormat String }==------------------;;
;;                                                            ;;
;;  Returns a string with all MText formatting codes removed. ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright ⓒ 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  str - String to Process                                   ;;
;;  mtx - MText Flag (T if string is for use in MText)        ;;
;;------------------------------------------------------------;;
;;  Returns:  String with formatting codes removed            ;;
;;------------------------------------------------------------;;

(defun LM:UnFormat ( str mtx / _replace rx )

    (defun _replace ( new old str )
        (vlax-put-property rx 'pattern old)
        (vlax-invoke rx 'replace str new)
    )
    (if (setq rx (vlax-get-or-create-object "VBScript.RegExp"))
        (progn
            (setq str
                (vl-catch-all-apply
                    (function
                        (lambda ( )
                            (vlax-put-property rx 'global     actrue)
                            (vlax-put-property rx 'multiline  actrue)
                            (vlax-put-property rx 'ignorecase acfalse) 
                            (foreach pair
                               '(
                                    ("\032"    . "\\\\\\\\")
                                    (" "       . "\\\\P|\\n|\\t")
                                    ("$1"      . "\\\\(\\\\[ACcFfHLlOopQTW])|\\\\[ACcFfHLlOopQTW][^\\\\;]*;|\\\\[ACcFfHLlOopQTW]")
                                    ("$1$2/$3" . "([^\\\\])\\\\S([^;]*)[/#\\^]([^;]*);")
                                    ("$1$2"    . "\\\\(\\\\S)|[\\\\](})|}")
                                    ("$1"      . "[\\\\]({)|{")
                                )
                                (setq str (_replace (car pair) (cdr pair) str))
                            )
                            (if mtx
                                (_replace "\\\\" "\032" (_replace "\\$1$2$3" "(\\\\[ACcFfHLlOoPpQSTW])|({)|(})" str))
                                (_replace "\\"   "\032" str)
                            )
                        )
                    )
                )
            )
            (vlax-release-object rx)
            (if (null (vl-catch-all-error-p str))
                str
            )
        )
    )
)
(vl-load-com)



 (setq ss (ssget '((0 . "*TEXT"))))
 (setq pt (getpoint "\n pick point to place result text"))
 (setq ssl (sslength ss))
 (if (= ssl 4)
     (progn ;(princ "\n yes 4 texts.")
        (setq ssindex 0)
        (setq textlist nil)
        (setq textstacklist nil)
        (repeat ssl
          (setq ent (entget (ssname ss ssindex)))
          (setq textcontents (LM:UnFormat (cdr (assoc 1 ent)) nil))
          (setq textlayer (cdr (assoc 8 ent)))
          (setq textsize (cdr (assoc 40 ent)))
          (setq textlist (list textlayer textcontents))
          (setq textstacklist (cons textlist textstacklist))
          (setq ssindex (+ ssindex 1))
        )

        ;sort by layer
        (setq textstacklist (vl-sort textstacklist
                                     (function
                                         (lambda (x1 x2)(< (car x1) (car x2)))
                                     )
                                  )
        )
        ;(princ textstacklist)               

        (setq text2write "")
        (setq text2write (strcat (vl-princ-to-string (cadr (nth 2 textstacklist))) "," (vl-princ-to-string (cadr (nth 0 textstacklist))) "," (vl-princ-to-string (cadr (nth 1 textstacklist))) "," (vl-princ-to-string (cadr (nth 3 textstacklist))) "/"))
        (princ text2write)
;|
      (entmake (list
                 '(0 . "MTEXT")
                 '(100 . "AcDbEntity")
                 '(100 . "AcDbMText")
                 (cons 10 pt)
                 (cons 1 text2write)
               )
      )

|;
        (entmake (list (cons 0 "TEXT")
                          (cons 1 text2write)
		  (cons 8 (car (nth 0 textstacklist)))
		  (cons 10 pt)
  		  (cons 40 textsize)
		  (cons 50 0)
	         )
         )

     )
     (progn (princ "\n no 4 texts.") (c:conc2))
 )

(princ)
)

 

Sorry among the masters,

this is a lisp that just merges 4 texts.

 

If you always have the same layer names order, will help.

If you select a number other than 4, it exits.

 

command is conc2

2022-02-22 18;07;58.PNG

 

 

and then use this TEXTEXPORT 

for export to csv excel file

 

 

 

Of course, if you sort those texts at the stage of making them, you will be able to print the list at once.

HI, thanks for the lisp files

 

I tried to use the TEXTEXPORT lisp, but after I select the text I get an error:

"error: bad argument type
error: bad argument type"

 

Need to mention that Im using Progecad 2021 / Intellicad - and Visual lisp not always works.

 

 

Edited by romparkin
Link to comment
Share on other sites

is there basic command "DATAEXPORT"?

in this case, just export text value in 1 column. it will usable.

it can export to csv or table inside of drawing also

 

or convert multiple text to 1 mtext with enter.

 

Link to comment
Share on other sites

4 hours ago, exceed said:

is there basic command "DATAEXPORT"?

in this case, just export text value in 1 column. it will usable.

it can export to csv or table inside of drawing also

 

or convert multiple text to 1 mtext with enter.

 

HI there is no Dataexport but there's a table export to csv, I will have to run some test too see if its faster using the tables
thanks for the tip

Romeo

Link to comment
Share on other sites

Ok try this version take care read the prompts, select "beton" blocks when asked, then zoom in to make sure you pick pline. 

 

image.png.0dce9e14564ab272957ec5f16ad2f930.png

 

; https://www.cadtutor.net/forum/topic/74514-text-concatenate-lisp-editing/

(defun c:test ( / ss ent obj pt ptpl ch off lst)

(vl-load-com)
(defun  ahmaketable (/ colwidth numcolumns numrows objtable rowheight sp vgad vgao vgms)
(vl-load-com)
(setq sp (vlax-3d-point (getpoint "pick a point for table")))
(Setq vgms (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))) ;
(setq numrows 3)
(setq numcolumns 4)
(setq rowheight 2.5)
(setq colwidth 60)
(setq objtable (vla-addtable vgms sp numrows numcolumns rowheight colwidth))
(vla-settext objtable 0 0 "Power poles "); TABLE TITLE
(vla-settext objtable 1 0 "Chainage ") 
(vla-settext objtable 1 1 "Offset") 
(vla-settext objtable 1 2 "ptx")
(vla-settext objtable 1 3"pty")
(command "_zoom" "e")
(princ)
)



(alert "\nSelect using window beton blocks \npress ok when ready ")

(setq ss (ssget (list (cons 0 "INSERT")(cons 2 "beton"))))

(setq ent (car  (entsel "\nPick alignment object pline")))
(setq obj (vlax-ename->vla-object ent))

(setq stch (getreal "\nPlease enter start chainage "))

(setq lst '())

(repeat (setq x (sslength ss))
(setq pt (cdr (assoc 10 (entget (ssname ss (setq x (1- x)))))))
(setq ptpl (vlax-curve-getclosestpointto obj pt))
(setq ch (+ stch (vlax-curve-getdistatpoint obj ptpl)))
(setq off (distance ptpl pt))
(setq lst (cons (list ch off pt) lst))
)

(ahmaketable )
(setq Objtable (vlax-ename->vla-object (entlast)))
(setq numrows 2)

(vla-put-regeneratetablesuppressed Objtable :vlax-true)

(setq lst (vl-sort lst '(lambda (x y) (< (car x)(car y)))))
(foreach val lst
(setq ch (car val)
off (cadr val)
ptx (car (caddr val))
pty (cadr (caddr val))
)
(setq numrows (1+ numrows))
(vla-InsertRows Objtable  numrows (vla-GetRowHeight Objtable (1- numrows)) 1)
(vla-settext objtable numrows 0 (rtos Ch 2 2)) 
(vla-settext objtable numrows 1 (rtos Off 2 2)) 
(vla-settext objtable numrows 2(rtos  ptx 2 2))
(vla-settext objtable numrows 3 (rtos pty 2 2))
)

(vla-put-regeneratetablesuppressed Objtable :vlax-false)
(princ)
)

 

It is feasible to write direct to WORD as its a Microsoft product like excel, I just dont know how to do as a Word table. Know how to do text. 

 

The attached is export table to excel.

table to excel.lsp

Edited by BIGAL
Link to comment
Share on other sites

Hi BIGAL

thanks for the hard work and time invested,

but I have some issues:

 

1. I used the last dwg I sent you, I select the points, I select the polyline, then add chainage, and after I click on insertion point for table I get and error.

 

"

Command: TEST
Select entities or [FILter/Qselect]: 
Opposite corner: 
Select entities or [FILter/Qselect]: 
Pick alignment object pline
Please enter start chainage 11
error: bad argument type
pick a point for table
error: too few arguments

"

 

I even tried to rename the "Power poles" layer to "beton" and the problem is the same. I tried to select the blocks, or to select the points, same problem.

Not sure if is something that Intellicad don't understands from Autolisp, or is something I do wrong...

 

Regards

Romeo

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...