Jump to content

Combine text and export


pmadhwal7

Recommended Posts

I got an idea but will only work with text in this orientation.

 

For now this allows multiple text to be change.

https://ibb.co/jHrcTRh

;;----------------------------------------------------------------------------;;
;; Add Prefix/Suffix to Text
(defun C:TXTEDIT (/ SS c rep prfx sufx)
  (prompt "\nSelect Text: ")
  (if (setq ss (ssget '((0 . "*TEXT"))))
    (progn
      (setq c 0)  ;Count
      (setq sufx (strcat " " (cdr (assoc 1 (entget (car (entsel "\nPick 2nd Text")))))))
      (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
        (setq txt (vlax-ename->vla-object ent))
        (vla-put-textstring txt (strcat (vla-get-TextString txt) sufx))
        (setq c (1+ c))
      )
      (if c
        (prompt (strcat "\n" (itoa c) " Text Updated"))
      )
    )
    (prompt "\nText Not Selected")
  )
  (princ)
)

 

Edited by mhupp
Link to comment
Share on other sites

10 hours ago, mhupp said:

I got an idea but will only work with text in this orientation.

 

For now this allows multiple text to be change.

https://ibb.co/jHrcTRh

;;----------------------------------------------------------------------------;;
;; Add Prefix/Suffix to Text
(defun C:TXTEDIT (/ SS c rep prfx sufx)
  (prompt "\nSelect Text: ")
  (if (setq ss (ssget '((0 . "*TEXT"))))
    (progn
      (setq c 0)  ;Count
      (setq sufx (strcat " " (cdr (assoc 1 (entget (car (entsel "\nPick 2nd Text")))))))
      (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
        (setq txt (vlax-ename->vla-object ent))
        (vla-put-textstring txt (strcat (vla-get-TextString txt) sufx))
        (setq c (1+ c))
      )
      (if c
        (prompt (strcat "\n" (itoa c) " Text Updated"))
      )
    )
    (prompt "\nText Not Selected")
  )
  (princ)
)

 

 

 

actually, every chainage has a different offset and this lisp merge one offset in all chainage, 

Ct lsp working like this:-

https://ibb.co/Q9m5PQF

Link to comment
Share on other sites

9 minutes ago, pmadhwal7 said:

 

 

actually, every chainage has a different offset and this lisp merge one offset in all chainage, 

Ct lsp working like this:-

https://ibb.co/Q9m5PQF

 

 

GIF means CT.LSP is not loaded. 

You should start by loading CT.LSP with APPLOAD.

Link to comment
Share on other sites

4 hours ago, pmadhwal7 said:

 

 

actually, every chainage has a different offset and this lisp merge one offset in all chainage, 

Ct lsp working like this:-

https://ibb.co/Q9m5PQF

 

If I am looking at it right, in your sample drawing there isn't an offset noted for each chainage distance? For example 7.300 offset is one text referring to a few chainages?

 

You might need to do this with 2 mouse clicks per chainage rather than selecting a lot of the text in one go. Select the chainage text and then the offset?

 

I have something similar to combine text but it is quite long for what you are wanting and would need some things removing. How are you with LISP routines? I have to go out shortly and not gong to get chance to do anything for you just now but this is what I would be thinking, and you might be able to put most of this together, asking again for clarification of the harder parts. Have a go, learn some stuff and it is more satisfying

 

Set up the LISP (defun and so on):

Make a blank list:

(setq MyTexts (list))

start a while loop here

Use MHUPPs example above to get text 1:

(setq prefx (strcat (cdr (assoc 1 (entget (car (entsel "\nPick 1st Text")))))))

Use MHUPPs example above to get text 2:

(setq sufx (strcat " " (cdr (assoc 1 (entget (car (entsel "\nPick 2nd Text")))))))

Join the 2 texts together:

(setq MyText (strcat prefx sufx)

(you can probably combine that step with the setq sufx step)

Append that to a list for exporting to Excel

(setq MyTexts (append Mytext MyTexts))

Update the original text using MHUPP from above:

(vla-put-textstring txt (strcat (vla-get-TextString txt) sufx))

End the while loop here then you can use the MyTexts list to export to a spreadsheet, or create a CSV file or whatever you need to do.

 

But for now, how about having a go at getting the above working, don't need to do the while loop yet, get that later. You'll probably need to do a bit of thinking

  • Like 1
Link to comment
Share on other sites

4 hours ago, Steven P said:

 

If I am looking at it right, in your sample drawing there isn't an offset noted for each chainage distance? For example 7.300 offset is one text referring to a few chainages?

 

You might need to do this with 2 mouse clicks per chainage rather than selecting a lot of the text in one go. Select the chainage text and then the offset?

 

I have something similar to combine text but it is quite long for what you are wanting and would need some things removing. How are you with LISP routines? I have to go out shortly and not gong to get chance to do anything for you just now but this is what I would be thinking, and you might be able to put most of this together, asking again for clarification of the harder parts. Have a go, learn some stuff and it is more satisfying

 

Set up the LISP (defun and so on):

Make a blank list:

(setq MyTexts (list))

start a while loop here

Use MHUPPs example above to get text 1:

(setq prefx (strcat (cdr (assoc 1 (entget (car (entsel "\nPick 1st Text")))))))

Use MHUPPs example above to get text 2:

(setq sufx (strcat " " (cdr (assoc 1 (entget (car (entsel "\nPick 2nd Text")))))))

Join the 2 texts together:

(setq MyText (strcat prefx sufx)

(you can probably combine that step with the setq sufx step)

Append that to a list for exporting to Excel

(setq MyTexts (append Mytext MyTexts))

Update the original text using MHUPP from above:

(vla-put-textstring txt (strcat (vla-get-TextString txt) sufx))

End the while loop here then you can use the MyTexts list to export to a spreadsheet, or create a CSV file or whatever you need to do.

 

But for now, how about having a go at getting the above working, don't need to do the while loop yet, get that later. You'll probably need to do a bit of thinking

Actually, i don't have any knowledge of LISP routines, and this lisp working on the only single text as i have too many texts and it was taking a very long time, exporting excel is not a very big thing after merging those offsets and chainages i have glamsen CadTools  i can export them but the only big thing is merging them one by one

Link to comment
Share on other sites

So working up what I suggested earlier. 

 

(defun c:tstthis ( / MyTexts EndLoop ent prefxent prefx sufx Mytext )
  (setq MyTexts (list))
  (setq EndLoop "No")

  (while (= EndLoop "No")
    (progn (setvar 'errno 0) (setq ent (car (entsel "\nPick First Text: ")))
      (cond
        ((= 52 (getvar 'errno))
          (setq EndLoop "Yes")
        )
        ((= 7 (getvar 'errno))
          (princ "\nMissed, try again.")
        )
        ((= 'ename (type ent))
          (setq prefxent (entget ent) )
          (setq prefx (strcat (cdr (assoc 1 prefxent ))))
          (setq sufx (strcat " " (cdr (assoc 1 (entget (car (entsel "\nPick 2nd Text")))))))
          (setq MyText (strcat prefx sufx))
          (setq MyTexts (append (list MyText) MyTexts))
          (setq prefxent (subst (cons 1 MyText) (assoc 1 prefxent) prefxent ) ) 
          (entmod prefxent)
        )
      ) ; end conds
    ) ;end progn
  ) ; end while

;;And now export to excel
;; Use MyTexts to do that
  (princ)
)

 

Edited by Steven P
Link to comment
Share on other sites

; ECT - 2022.05.26 exceed
; https://www.cadtutor.net/forum/topic/75239-combine-text-and-export/
; - what is this
; Text content is concatenated between texts close to each other.
; 
; - how to use
; 1. select a group of text twice.
; 2. overwriting the text of the 1st selected group.
;
; - note 
; 1. Because it simply works on distance-based,
;    It's not a 1:1 pair. For example, if text group2 is less than group1, the closest group2 is copied.
; 2. If there is text with overlapping positions, it may not work properly.

(vl-load-com)
(defun c:ECT ( / ss ssl index1 ss1list obj1 coord1 list1 ss2 ss2l index2 ss2list obj2 coord2 list2 pairstack index11 coord11 index22 coord22 dist12 distlist distmin pslen psindex txt1 txt2 puttxt )

(princ "\n pick 1st group of text")
(setq ss (ssadd)) 
(setq ss (ssget ":L" '((0 . "*TEXT"))))
(setq ssl (sslength ss))

(if (/= ssl 0)
  (progn
    (setq index1 0)
    (setq ss1list '())
    ;make 1st list
    (repeat ssl
      (setq obj1 (vlax-ename->vla-object (ssname ss index1)))
      (setq coord1 (vlax-safearray->list (vlax-variant-value (vlax-get-property obj1 'InsertionPoint))))
      (setq list1 (list obj1 coord1))
      (setq ss1list (cons list1 ss1list))
      (setq index1 (+ index1 1))
    )

    (princ "\n pick 2nd group of text")
    (setq ss2 (ssget ":L" '((0 . "*TEXT"))))
    (setq ss2l (sslength ss2))
    (setq index2 0)
    (setq ss2list '())
    ;make 2nd list
    (repeat ss2l
      (setq obj2 (vlax-ename->vla-object (ssname ss2 index2)))
      (setq coord2 (vlax-safearray->list (vlax-variant-value (vlax-get-property obj2 'InsertionPoint))))
      (setq list2 (list obj2 coord2))
      (setq ss2list (cons list2 ss2list))
      (setq index2 (+ index2 1))
    )
   
    (setq pairstack '())
    (setq index11 0)
    (repeat ssl
      (setq coord11 (cadr (nth index11 ss1list)))
      (setq index22 0)

        (setq distlist '())
        (repeat ss2l
          (setq coord22 (cadr (nth index22 ss2list)))
          (setq dist12 (distance coord11 coord22))
          (setq distlist (cons (list (car (nth index22 ss2list)) dist12) distlist))
          (setq index22 (+ index22 1))
        )
        (setq distlist (vl-sort distlist (function (lambda (x1 x2)(< (cadr x1) (cadr x2))) ) ))
        (setq distmin (car (car distlist)))
        (setq pairlist (list (car (nth index11 ss1list)) distmin))
        (setq pairstack (cons pairlist pairstack))

      
      (setq index11 (+ index11 1))
    )

    (setq pslen (length pairstack))
    (setq psindex 0)

    (repeat pslen
      (setq txt1 (car (nth psindex pairstack)))
      (setq txt2 (cadr (nth psindex pairstack)))
      (setq puttxt (strcat (vlax-get-property txt1 'TextString) " / " (vlax-get-property txt2 'TextString)))
      (vlax-put-property txt1 'TextString puttxt)
      (setq psindex (+ psindex 1))
    )

  );end of progn
);end of if

(princ)
);end of defun

ct2.gif

 

COMMAND : ECT

 

You should check the areas with overlapping or densed text. it makes error.

Edited by exceed
  • Like 3
Link to comment
Share on other sites

Exceed I need more time to look but I did something similar to a schedule of 5 columns, so need opposite of  XY rather sort YX, it also took into account blanks, the reason I mention is just window select all text. It had hundreds of lines and and end result was a list. When you sort the Y's you should get 2 values with same Y plus tolerance  if not then second is blank. I looked at nth x & nth x+1 comparing using equal with a tolerance, in this case on x which is opposite for me.

 

The sample has something to do with road design so I doubt it will ever be on an angle.

 

Ps I wrote it as version 2 for a customer the end task was convert column text to a table for the future. Found one out there but used lines for boxes around text, no good for me as did multiple schedules in one window pick. It had variable line spacing.

 

XY sort

(setq lst (vl-sort lst
	 '(lambda (a b)
	    (cond
	      ((< (car a) (car b)))
	      ((= (car a) (car b) ) (< (cadr a) (cadr b)))
	    )
	  )
       )
)

 

  • Thanks 1
Link to comment
Share on other sites

@exceed

 

looking at your gif, I suppose, you could avoid selecting twice... Perhaps, consider something like this (given the fact that one group of text entities is with starting syntax "CH*" (chainage) )...

 

...
(setq sstxt (ssget "_:L" '((0 . "TEXT")))) ;;; only single selection needed ;;;

 

(setq ss1 (ssget "_P" '((1 . "CH*"))))

...
(sssetfirst nil sstxt)
(setq ss2 (ssget "_I" '((1 . "~CH*"))))
...

 

Altentatively for ss2, you could also use (acet-ss-remove) function with sstxt and ss1...

Edited by marko_ribar
  • Like 1
Link to comment
Share on other sites

Well got it to work with one big window selection but there is to many other problems in the sample dwg, some of the offset text is twice so screws thing up, in other locations there is no offset. In another spot the offset has been moved away from the vertical line so a different x value to work with. I used overkill 1st then added "." for all the missing values. It looks like some text was 3 times.

 

So as dwg is not consistent have not posted code at this stage. 

 

I need to add the offset is blank by comparing the x values with a fuzz factor for pairs of items in the master lst.

 

 

 

 

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...