Author Topic: Dimension sum to text sum routine converting  (Read 7817 times)

0 Members and 1 Guest are viewing this topic.

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Dimension sum to text sum routine converting
« on: April 11, 2018, 10:01:31 AM »
The first attached routine (Dimension Sum Export - DS.lsp) can sum dimension values and export it to text file in format A+B+C+.. = Sum
I need to convert/add to this routine option for numeric text sum and numeric block attributes (optional) and export it in a same format.
Second attached routine (add.lsp) can do this process but have a different export format
Is it possible to combine these routines?
Any help will be very appreciated
« Last Edit: April 11, 2018, 10:04:36 AM by danglar »

Dlanor

  • Bull Frog
  • Posts: 263
Re: Dimension sum to text sum routine converting
« Reply #1 on: April 11, 2018, 08:41:06 PM »
Quick and dirty. No check if selected text is a number.

Code - Auto/Visual Lisp: [Select]
  1. ; Select Text Numbers. A right mouse button click (if set to enter) or press enter to end selection.
  2.  
  3. (defun C:txt+ (/ c_doc ent ss t_lst xport_str fn file)
  4.         (prompt "\nPick Text numbers to add : ")
  5.                 ent (ssget '((0 . "TEXT")))
  6.                 ss (vla-get-activeselectionset c_doc)
  7.                 xport_str ""
  8.         )
  9.         (vlax-for obj ss
  10.                 (setq t_lst (cons (atof (vla-get-textstring obj)) t_lst))
  11.                 (if (= (strlen xport_str) 0)
  12.                         (setq xport_str (strcat xport_str (vla-get-textstring obj)))           
  13.                         (setq xport_str (strcat xport_str " + " (vla-get-textstring obj)))
  14.                 )
  15.         )
  16.         (setq xport_str (strcat xport_str " = " (rtos (apply '+ t_lst) 2 3))
  17.                 ss nil
  18.                 fn (strcat (getvar "dwgprefix") "????? Export Report.txt");<<====ADJUST TO WHAT YOU REQUIRE    
  19.                 file (open fn "a") ; append
  20.         )
  21.         (write-line "" file)
  22.         (princ xport_str file)
  23.         (close file)
  24.         (startapp "notepad.exe" fn)
  25. )
  26.  
  27.  

I cannot accomodate numeric block attributes as these require selecting individually using nentsel as opposed to the ssget where you can select by bulk if required.

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Re: Dimension sum to text sum routine converting
« Reply #2 on: April 12, 2018, 04:54:47 AM »
Thank you Dlanor
Is it possible to include this solution as apart of main program?
Something like this: s (ssget (list '(0 . "DIMENSION,TEXT"))))

Dlanor

  • Bull Frog
  • Posts: 263
Re: Dimension sum to text sum routine converting
« Reply #3 on: April 12, 2018, 05:54:09 AM »
Is it possible to include this solution as apart of main program?
Something like this: s (ssget (list '(0 . "DIMENSION,TEXT"))))

If i can find the time i'll give it a go.

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Re: Dimension sum to text sum routine converting
« Reply #4 on: April 12, 2018, 05:55:08 AM »
thank you anyway..

Dlanor

  • Bull Frog
  • Posts: 263
Re: Dimension sum to text sum routine converting
« Reply #5 on: April 12, 2018, 11:08:08 AM »
OK, completed. Hope this is what you require. Once again there is NO checking that selected text items only contain numbers.

Code - Auto/Visual Lisp: [Select]
  1. ;; Select Dimensions or Text Numbers.
  2. ;; A right mouse button click (if set to enter) or press enter to end selection.
  3. ;; Be aware discrepancies may arise due to rounding required
  4.  
  5. (defun c:ds (/ c_doc ent ss t_lst xport_str fn file txt_num)
  6.        (prompt "\nPick Text numbers to add : ")
  7.                 ent (ssget '((0 . "TEXT,DIMENSION")))
  8.                 ss (vla-get-activeselectionset c_doc)
  9.                 xport_str ""
  10.         )
  11.         (vlax-for obj ss
  12.                 (setq txt_num nil)
  13.                 (cond ( (wcmatch (vla-get-objectname obj) "*Dimension")
  14.                                                         (if (/= (vla-get-textoverride obj) "")
  15.                                                                 (setq txt_num (atof (vla-get-textoverride obj)))
  16.                                                                 (setq txt_num (vla-get-measurement obj))
  17.                                                         )
  18.                                         )
  19.                                         (       (wcmatch (vla-get-objectname obj) "*Text")
  20.                                                         (setq txt_num (atof (vla-get-textstring obj)))
  21.                                         )
  22.                 )
  23.                 (if txt_num
  24.                         (progn
  25.                                 (setq t_lst (cons txt_num t_lst))
  26.                                 (if (= (strlen xport_str) 0)
  27.                                         (setq xport_str (strcat xport_str (rtos txt_num 2 1)))         
  28.                                         (setq xport_str (strcat xport_str "+" (rtos txt_num 2 1)))
  29.                                 )
  30.                         )
  31.                 )
  32.         )
  33.         (setq xport_str (strcat xport_str "=" (rtos (apply '+ t_lst) 2 1))
  34.                  ss nil
  35.                  fn (strcat (getvar "dwgprefix") "Dimension Export Report.txt")
  36.                  file (open fn "a"); append
  37.         )
  38.         (write-line "" file)
  39.         (princ xport_str file)
  40.         (close file)
  41.         (startapp "notepad.exe" fn)
  42.         (princ)
  43. )
  44. ;(c:ds)
  45.  
  46.  

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
Re: Dimension sum to text sum routine converting
« Reply #6 on: April 12, 2018, 11:15:16 AM »
Thank you Dlanor
Is it possible to include this solution as apart of main program?
Something like this: s (ssget (list '(0 . "DIMENSION,TEXT"))))
I would like to see you write some code on your own one day.
TheSwamp.org  (serving the CAD community since 2003)

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Re: Dimension sum to text sum routine converting
« Reply #7 on: April 13, 2018, 05:44:37 AM »
Thank you Dlanor.
I very appriciate your help.
I would like to see it too Mark. I spend a lot of time to write my own codes and I have some progress in my tryings, but I achived sucsess only in modifications of existing codes. Whats why I'm here in a swamp.. to learn from guru's how to do it well

Dlanor

  • Bull Frog
  • Posts: 263
Re: Dimension sum to text sum routine converting
« Reply #8 on: April 13, 2018, 03:04:23 PM »
Thank you Dlanor.
I very appriciate your help.

Not a problem. I still can't figure out how to get attributes in there. I can do text and attributes but it would mean losing the dimensions.  :nerdyembarassed:

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Dimension sum to text sum routine converting
« Reply #9 on: April 14, 2018, 02:36:16 PM »
Thank you Dlanor.
I very appriciate your help.

Not a problem. I still can't figure out how to get attributes in there. I can do text and attributes but it would mean losing the dimensions.  :nerdyembarassed:

Just running through, but you can use the routine here to select attributes with window or crossing:  https://www.theswamp.org/index.php?topic=19886.msg488544#msg488544
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Dlanor

  • Bull Frog
  • Posts: 263
Re: Dimension sum to text sum routine converting
« Reply #10 on: April 14, 2018, 06:20:06 PM »
Just running through, but you can use the routine here to select attributes with window or crossing:  https://www.theswamp.org/index.php?topic=19886.msg488544#msg488544

Thanks, I'll check it out, although i've found another solution. Nentsel returns the parent entity as the last item in the list it returns. This allows me to sidestep parsing the formatted mtext string, and also allows any sub entity of the dimension to be selected to get to the parent entity and it's object.

Being brain dead,  I was looking for it in the entget data for the selected sub entity.  :idiot2:

Not what the OP needs, and it still needs a bit of tarting up and error checking

Code - Auto/Visual Lisp: [Select]
  1. (defun c:addtxts (/ c_doc ent e_len ss t_lst xport_str fn file txt_num)
  2.  
  3.  
  4.         (while (setq ent (nentsel "\nSelect Dimensions, Text Numbers or Attributes to Add : "))
  5.                 (if ent
  6.                         (progn
  7.                                 (setq e_len (length ent))
  8.                                 (if (> e_len 2)                                                                                                
  9.                                         (setq ent (car (nth (1- e_len) ent)))  
  10.                                         (setq ent (car ent))
  11.                                 )
  12.                                 (setq obj (vlax-ename->vla-object ent))
  13.                                 (cond ( (or (= (vla-get-objectname obj) "AcDbAlignedDimension") (= (vla-get-objectname obj) "AcDbArcDimension"))
  14.                                                                         (setq txt_num (vla-get-measurement (vlax-ename->vla-object ent))
  15.                                                                               t_lst (cons txt_num t_lst)
  16.                                                                         )
  17.                                                         )
  18.                                                         (       (or (= (vla-get-objectname obj) "AcDbText") (= (vla-get-objectname obj) "AcDbAttribute"))
  19.                                                                         (setq m_txt (if (= (vla-get-objectname obj) "AcDbAttribute") "Attribute" "Text")
  20.                                                                               txt_num (rh:get_num (vla-get-textstring (vlax-ename->vla-object ent)))
  21.                                                                         )
  22.                                                                         (if (numberp txt_num)
  23.                                                                                 (setq t_lst (cons txt_num t_lst))
  24.                                                                                 (alert (strcat "Selected " m_txt " is NOT a number"))
  25.                                                                         )
  26.                                                         )
  27.                                                         (t
  28.                                                                 (alert "Not a Distance Dimension, Text or Attribute")
  29.                                                         )
  30.                                 )
  31.                         )      
  32.                 )
  33.         )
  34.         (alert (strcat "Total = " (rtos (apply '+ t_lst) 2 3)))
  35. )
  36.  

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Re: Dimension sum to text sum routine converting
« Reply #11 on: April 15, 2018, 05:00:42 AM »
Hi Dlanor.
I have some notes to published solution:
1. Solution needs internal function rh:get_num (this is not mentioned in published code)
2. Program works only with aligned or arc dimensions..
is it possible to publish get_num function and include all versions of dimensions in a routine?
Another question: Is it possible to include this common solution to main routine with output mentioned in my first post?

Dlanor

  • Bull Frog
  • Posts: 263
Re: Dimension sum to text sum routine converting
« Reply #12 on: April 15, 2018, 06:43:00 AM »
Hi Dlanor.
I have some notes to published solution:
1. Solution needs internal function rh:get_num (this is not mentioned in published code)
2. Program works only with aligned or arc dimensions..
is it possible to publish get_num function and include all versions of dimensions in a routine?
Another question: Is it possible to include this common solution to main routine with output mentioned in my first post?

If you read my previous post again; i've stated that it is NOT what you (the OP) wants and that it is NOT the finished article. The missing function was my oversight and is below

Code - Auto/Visual Lisp: [Select]
  1. (defun rh:get_num ( txt )
  2.         (if (= (vl-string-trim ".0123456789" txt) "")
  3.                 (setq txt (atof txt))
  4.                 (setq txt '())
  5.         );end_if
  6. );end_defun
  7.  
  8.  


danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Re: Dimension sum to text sum routine converting
« Reply #13 on: April 15, 2018, 06:53:56 AM »
sorry for misunderstanding..  :uglystupid2:
what's about the rest of my questions?

Dlanor

  • Bull Frog
  • Posts: 263
Re: Dimension sum to text sum routine converting
« Reply #14 on: April 15, 2018, 02:41:27 PM »
what's about the rest of my questions?

There are 5 sorts of dimensions, linear, radial, angular, ordinate, and arc length. I can't see why you would need to include radial or ordinate, but look them up and decide which you want including.

https://knowledge.autodesk.com/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2018/ENU/AutoCAD-Core/files/GUID-9A8AB1F2-4754-444C-B90D-CD3F2FC8A3E0-htm.html

If you do want any additions to those existing it will mean providing additional checks so that you cannot inadvertantly add linear and angular together etc.

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Re: Dimension sum to text sum routine converting
« Reply #15 on: April 16, 2018, 01:40:18 AM »
I thinking about dimensions.. On this stage I decide I need linear dimensions only + numeric texts + block attributes (optional) without mtext. I understand, this is no so simple, but I do't want to lose a hope

Dlanor

  • Bull Frog
  • Posts: 263
Re: Dimension sum to text sum routine converting
« Reply #16 on: April 16, 2018, 10:40:34 AM »
I thinking about dimensions.. On this stage I decide I need linear dimensions only + numeric texts + block attributes (optional) without mtext. I understand, this is no so simple, but I do't want to lose a hope

OK, I'll try to finish it tomorrow.

Dlanor

  • Bull Frog
  • Posts: 263
Re: Dimension sum to text sum routine converting
« Reply #17 on: April 17, 2018, 06:03:02 AM »
Attached is lisp. Please read the comments at the top of the file.

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Re: Dimension sum to text sum routine converting
« Reply #18 on: April 17, 2018, 07:04:30 AM »
First of all thank you Dlanor for an excellent routine!
After my checking a conclusion is: all working properly among dimensions texts and block attributes
Remain only one question. Is it possible to highlight selected entities like in ssget function?
In common case will be better to use ssget function with window selecting. In your case we need to select needful objects one by one and if the object not highlighted difficult to know if it already selected...

Dlanor

  • Bull Frog
  • Posts: 263
Re: Dimension sum to text sum routine converting
« Reply #19 on: April 17, 2018, 08:09:53 AM »
Off the top of my head, No. You can highlight the text and dimensions, but not the block attribute, only the block itself without losing the other highlighted objects. 

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Re: Dimension sum to text sum routine converting
« Reply #20 on: April 17, 2018, 08:18:24 AM »
well. how to highlight the texts and dimensions?
Can you improve it in the routine?

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
TheSwamp.org  (serving the CAD community since 2003)

Dlanor

  • Bull Frog
  • Posts: 263
Re: Dimension sum to text sum routine converting
« Reply #22 on: April 17, 2018, 08:34:38 AM »
well. how to highlight the texts and dimensions?
Can you improve it in the routine?

Is that highlight the text and dims and not the blocks, or highlight everything selected?

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Re: Dimension sum to text sum routine converting
« Reply #23 on: April 17, 2018, 08:44:42 AM »
I thinking about it.. It seems to me better to highlight everything selected.. better to manage selected objects and divide it from not selected objects

Dlanor

  • Bull Frog
  • Posts: 263
Re: Dimension sum to text sum routine converting
« Reply #24 on: April 17, 2018, 11:09:45 AM »
Attached is update lisp to highlight selected dims, text and the parent block of the selected attribute. The highlighted items are reset as the lisp exits.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Dimension sum to text sum routine converting
« Reply #25 on: April 17, 2018, 01:44:17 PM »
Dlanor,

FYI:  You can use the 'redraw' function to highlight entities (works with attributes).  Click on the 'redraw' name in the code below to see the man page for it.

Code - Auto/Visual Lisp: [Select]
  1. (setq sel (nentsel))
  2. (redraw (car sel) 3)
  3. ; (redraw (car sel) 4) ; this will un-highlight
  4.  
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Re: Dimension sum to text sum routine converting
« Reply #26 on: April 17, 2018, 03:15:08 PM »
thank you very match Dlanor. your help is very appreciated by me especially on your birthday.
 all works like a charm and like I need.
you are the real MASTER :smitten:

Dlanor

  • Bull Frog
  • Posts: 263
Re: Dimension sum to text sum routine converting
« Reply #27 on: April 17, 2018, 03:49:43 PM »
you are the real MASTER :smitten:

In truth, i'm barely a youngling compared to most here.   :embarrassed:

Dlanor

  • Bull Frog
  • Posts: 263
Re: Dimension sum to text sum routine converting
« Reply #28 on: April 17, 2018, 05:37:51 PM »
Dlanor,

FYI:  You can use the 'redraw' function to highlight entities (works with attributes).  Click on the 'redraw' name in the code below to see the man page for it.

Code - Auto/Visual Lisp: [Select]
  1. (setq sel (nentsel))
  2. (redraw (car sel) 3)
  3. ; (redraw (car sel) 4) ; this will un-highlight
  4.  

Sorry but I missed this earlier. At the moment i'm highlighting the Block but this works much better. Many Thanks  :yay!:


Dlanor

  • Bull Frog
  • Posts: 263
Re: Dimension sum to text sum routine converting
« Reply #30 on: April 18, 2018, 03:55:26 AM »
danglar,

please find attached a more elegant solution thanks to Tim Willey.

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Re: Dimension sum to text sum routine converting
« Reply #31 on: April 18, 2018, 04:10:53 AM »
You are right. Now it become more elegant (when you select block with attribute - only needful attribute selected)
Published solution updated  on my blog with additional thanks to Tim Willey