Progress Bar in lisp code

Progress Bar in lisp code

mhy3sx
Enthusiast Enthusiast
3,887 Views
42 Replies
Message 1 of 43

Progress Bar in lisp code

mhy3sx
Enthusiast
Enthusiast

Hi, I use this code to insert points in a drawing from a coordinate file. The problem is that when I have a lot of coordinates in the file the code is a little slow, so I want to have a progress bar to look the progress of the insert points. Can anyone help me to update the code ?

 

Thanks

0 Likes
3,888 Views
42 Replies
Replies (42)
Message 2 of 43

mhy3sx
Enthusiast
Enthusiast

Is possible to do this?

0 Likes
Message 3 of 43

hosneyalaa
Advisor
Advisor
0 Likes
Message 4 of 43

mhy3sx
Enthusiast
Enthusiast
Hi hosneyalaa , I have seen this link but I don't know how to use it in my code. In this link have a dcl menu with start button , I wan't to start when insert the points and in some way this progress bar will be related with the number of the points in the file. Can you help with the code ?

Thanks
0 Likes
Message 5 of 43

paullimapa
Mentor
Mentor

unfortunately cannot call up a dialog box while inserting points into the drawing area

you might be able to implement express tools progress bar version in the status area but just not as apparent:

https://forums.augi.com/showthread.php?46371-The-Progress-Bar-in-the-AutoCAD-status-Area


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 6 of 43

CADaSchtroumpf
Advisor
Advisor

Give this a try, it's up to you to insert it into your code...

((lambda ( / a size b line progress i)
  (setq a (getfiled "Points data file" "" "" 4))
  (if (= a 1)
    (progn
      (setq a "")
      (while (eq (findfile a) ())
        (setq a (getstring "\nPoints data file"))
        (if (= a ()) (setq a ""))
        (if (not (findfile a))
          (princ "\nFile name not found or invalid!")
        )
      )
    )
  )
  (cond
    (a
      (setq
        size (vl-file-size a)
        b (open a "r")
        a (read-line b)
        line (strlen a)
        progress (fix (/ size line))
        i 0
      )
      (acet-ui-progress-init "Working:" progress)
      (while a
        (setq a (read-line b))
        (acet-ui-progress-safe (setq i (1+ i)))
      )
      (acet-ui-progress)
      (close b)
    )
  )
  (prin1)
))
0 Likes
Message 7 of 43

john.uhden
Mentor
Mentor

@mhy3sx ,

DOSLIB has a dos_progressbar function that will do what you want.  And it's free.

John F. Uhden

0 Likes
Message 8 of 43

mhy3sx
Enthusiast
Enthusiast

The code is not mine and it is too complicate for me. Can any one add the progress bar in the code?

Thanks

0 Likes
Message 9 of 43

Sea-Haven
Mentor
Mentor

Happy to do send the beer to ...........

 

Having a go at doing it is all part of the learning process. Close the dcl and run the import function the sample acet code above can be used. 

0 Likes
Message 10 of 43

CADaSchtroumpf
Advisor
Advisor

@mhy3sx  a écrit :

The code is not mine and it is too complicate for me. Can any one add the progress bar in the code?

Thanks


This code is not mine either. So adding my suggestion is complicated for me too.
If you want to try this version which is mine, for me it's simpler.

0 Likes
Message 11 of 43

Sea-Haven
Mentor
Mentor

Another example.

;; EXAMPLE LISP SHORT VERSION
(defun c:test(/ progress)
(defun progressbar (a b c d)
(cond ((= 0 a)
(acet-ui-progress-init d 100)
(setq c 0)
)
((= 1 a)
(setq c (+ (/ 100.0 b) c))
(acet-ui-progress-safe c)
)
((= 2 a)
(acet-ui-progress-done)
)
)
c
)
; I would read the file and make a list here of PENZD

(setq repeatvariable 1000) ; change to (setq repeatvariable (length list))
(setq progress (Progressbar 0 repeatvariable progress "Processing:")) ;Create the progress bar, total length is repeatvariable or 10000
(repeat repeatvariable
(setq progress (Progressbar 1 repeatvariable progress "")) ;arg (a) is set to 1 and (d) can be blank here
; do your read item from list and make new points
)
(Progressbar 2 0 0 "") ;arg(a) is set to 2 to close the progress bar, arg (b), (c) & (d) can be blanks
)
0 Likes
Message 12 of 43

mhy3sx
Enthusiast
Enthusiast
Hi CADaSchtroumpf, I try your code but ask for a lot of settings and at the end not insert anything. I will stay with my code.
0 Likes
Message 13 of 43

mhy3sx
Enthusiast
Enthusiast
Hi Sea-Haven. How to add this code in pointsin.lsp ?

Thanks
0 Likes
Message 14 of 43

Sea-Haven
Mentor
Mentor

Again because you have posts here and Cadtutor and The swamp its confusing just put a post to put all suggestion to one forum I know  will look at others. 

 

Re points in looking at code and think could be halved, seems to have to many steps, as no dwg showing result required makes it a bit harder. Like John K "The Swamp" I would just write it all from scratch with all your requests contained in one program.

 

Looking for sample text file.

0 Likes
Message 15 of 43

mhy3sx
Enthusiast
Enthusiast

Ok you are right. I put all together in this post.

 

1) I want to add a dcl menu  in the code. I write this part of the code, the lisp run ,open dcl file , select the coordinate file  but gives me this error

 

error: malformed list on input
error: invalid argument type: listp:

 

 

 

, and I can not find what is the problem

 

 

 

(defun PI:GETFILEFORMAT (/ )

      (defun *error* ( / *error* dch dcl des)
        (if (and (= 'int (type dch)) (< 0 dch))
          (unload_dialog dch)
        )
        (if (= 'file (type des))
          (close des)
        )
        (if (and (= 'str (type dcl)) (findfile dcl))
          (vl-file-delete dcl)
        )

        (princ)
      ) ; end defun
     
      (cond
        ( (not
            (setq dcl (vl-filename-mktemp nil nil ".dcl")
                 des (open dcl "w")
            ) ; end setq
          ) ; end not
          (princ "\nUnable to open DCL for writing.")
        )
        ( (progn
            (foreach str '(
                            "ed : edit_box { alignment = left; width = 20; edit_width = 10; fixed_width = true;}"
                            ""
                            "pointsin : dialog { spacer; key = \"dcl\";"
                            " : boxed_column { label = \"Text Style\"; height = 1.0;}"
                            "      : radio_button { height = 1.0; width = 20; is_tab_stop = true;"
                            "        key = \"radio_button01\"; label = \"1. PNEZD (comma delimited)\";"
                            "    }" ; radio_button 
                            "      : radio_button  { height = 1.0; width = 20; is_tab_stop = true;"
                            "        key = \"radio_button02\"; label = \"2.  PNEZD (tab delimited)\";"
                            "    }" ; radio_button 
                            "      : radio_button  { height = 1.0; width = 20; is_tab_stop = true;"
                            "        key = \"radio_button03\"; label = \"3.PNEZD (white-space delimited)\";"
                            "    }" ; radio_button 
                            "      : radio_button  { height = 1.0; width = 20; is_tab_stop = true;"
                            "        key = \"radio_button04\"; label = \"4. PENZD (comma delimited)\";"
                            "    }" ; radio_button 
                            "      : radio_button  { height = 1.0; width = 20; is_tab_stop = true;"
                            "        key = \"radio_button05\"; label = \"5. PENZD (tab delimited)\";"
                            "    }" ; radio_button 
                            "      : radio_button { height = 1.0; width = 20; is_tab_stop = true;"
                            "        key = \"radio_button06\"; label = \"6. PENZD (white-space delimited)\";"
                            "    }" ; radio_button 
                            "    : row { width = 20;"
                            "      : button { key = \"OK\"; label = \"OK\"; is_default = true;"
                            "                 is_cancel = true; fixed_width = true; width = 10; }" 
                            "    }" ; end row
                            "  }" ; end dialog
                          ) ;end list
              (write-line str des)
            ) ; end foreach
            (setq des (close des)
                 dch (load_dialog dcl)
            ) ; end setq
            (<= dch 0)
          )
          (princ "\nUnable to load DCL file.")
        )
        (   (not (new_dialog "pointsin" dch))
            (princ "\nUnable to display 'pointsin' dialog.")
        )
        ( t
          (set_tile "dcl" "Select file")
		(setq FILEFORMAT1)
          (action_tile "radio_button01" "(setq FILEFORMAT 1))")
          (action_tile "radio_button02" "(setq FILEFORMAT 2))")
          (action_tile "radio_button03" "(setq FILEFORMAT 3))")
          (action_tile "radio_button04" "(setq FILEFORMAT 4))")
          (action_tile "radio_button05" "(setq FILEFORMAT 5))")
          (action_tile "radio_button06" "(setq FILEFORMAT 6))")
          (action_tile "OK" "(progn (done_dialog 1) FILEFORMAT)")
          (start_dialog)
        )
      ) ; end cond
      (*error* nil)
    (princ)
) ;_  end defun

 

 

 

2) Is to add the progress bar in the code, bacause some times the files are big ,have a lot of coordinates and I want to know that the code working and how match time need to finish.

 

I upload again the working  poinsin.lsp  without any changes , the *.dwg file and a coodrinate file for option 4 with P,E,N,Z,D

 

This is all the updates I need to do in this code.

Can anyone help me?

 

Thanks

 

0 Likes
Message 16 of 43

Sea-Haven
Mentor
Mentor

I dont think you need a progress bar I just read 400 points and it was instant. 

 

 

 

; Import csv or space or tab delimeted file PENZD
; By AlanH April 2024

(defun c:mhy3sximport ( / csv->lst del fo fname but blk lst oldsnap curspace)

; thanks to lee-mac for this defun
(defun csv->lst ( str / pos )
(if (setq pos (vl-string-position del str))
    (cons (substr str 1 pos) (csv->lst (substr str (+ pos 2))))
    (list str)
    )
)
(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)

(setq fname (getfiled "CSV FILES" "SETOUT" "CSV" 16))
(setq fo (open fname "R"))

(setq lst '())

(if (not AH:Butts)(load "Multi radio buttons.lsp")) 			; loads the program if not loaded already
(setq ans (ah:butts 1 "V"   '("Please choose " "Comma ," "Semicolon ;" "Space " "Tab" ))) 	; ans holds the button picked value as a string

(cond 
  ((= but 1)(setq del 44))
  ((= but 2)(setq del 59))
  ((= but 3)(setq del 32))
  ((= but 4)(setq del 9))
)

(while (setq nline (read-line fo))
  (setq lst (cons (csv->lst nline) lst))
)
(close fo)

(if (tblsearch "Block" "point")
(princ)
(progn
(setvar 'atreq 0)
(command "-insert" "c:\\myblock\\point.dwg" "0,0" 1 1 0)
(command "erase" (entlast) "")
)
)

(setq curspace (vlax-get-property
    (vla-get-activedocument (vlax-get-acad-object))
    (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace)
    )
)

(foreach cogo lst
  (setq 
   ptnum (nth 0 cogo)
   pt (list (atof (nth 1 cogo))(atof (nth 2 cogo)))
   z (nth 3 cogo)
   desc (nth 4 cogo)
  )
  
  (vla-insertblock curspace (vlax-3D-point pt) "POINT" 1 1 1 0)
  (setq blk (vlax-ename->vla-object (entlast)))
  (setq atts (vlax-invoke blk 'Getattributes))
  (vlax-put (nth 0 atts) 'textstring desc)
  (vlax-put (nth 1 atts) 'textstring ptnum)
  (vlax-put (nth 2 atts) 'textstring z)
)

(setvar 'osmode oldsnap)

(princ)
)
(c:mhy3sximport)

 

 

 

 

I know you have Multi radio buttons.lsp. 

Dummied up excel -> csv

SeaHaven_0-1713781007051.png

Use this dwg as it has the block "PDE" it must exist its made up of your 3 attdef's.

0 Likes
Message 17 of 43

CADaSchtroumpf
Advisor
Advisor

@mhy3sx  a écrit :
Hi CADaSchtroumpf, I try your code but ask for a lot of settings and at the end not insert anything. I will stay with my code.

My code aims to be as versatile as possible.
It allows you to order the columns of the read file to assign the right data in the drawing.
Here is the procedure with your example of text file as well as the result in image, nothing very complicated...


Commande: READFILE2BLK
1,288175.214,4219902.655,28.397,description
Separator [SPace/Comma/SEmicolon/Tabulation]? <SEmicolon>: C
1 288175.214 4219902.655 28.397 description
This 1st line is it a header line which can constitute the attribute labels [Yes/No]? <No>:

Element 1 is [Data/Xlocation/Ylocation/Zlocation/Ignore]?: D

Element 288175.214 is [Data/Xlocation/Ylocation/Zlocation/Ignore]?: X

Element 4219902.655 is [Data/Ylocation/Zlocation/Ignore]?: Y

Element 28.397 is [Data/Zlocation/Ignore]?: Z

Element description is [Data/Ignore]?: D

Block scale? <1>: 0.25


readFile2BLK.png

Message 18 of 43

mhy3sx
Enthusiast
Enthusiast

Dont try to change the lisp code .I want to use pointsin.lsp.

 

I delete my radio button code and replace the code with Multi radio buttons.lsp but I get

 

 

Trapped error: invalid argument type: listp: 3

 

 

 

 

(DEFUN PI:GETFILEFORMAT (/)

(if (not AH:Butts)(load "Multi radio buttons.lsp")) ; loads the program if not loaded already
(setq ans (atoi (ah:butts 1 "V"   '("Please choose " "2. PΥΧZD  tab" "3. PΥΧZD space" "4. PΧΥZD comma " "5. PΧΥZD tab" "6. PΧΥZD space)")))) 	; ans holds the button picked value as a string

(cond 
  ((= but 1)(setq fileformat 1))
  ((= but 2)(setq fileformat 2))
  ((= but 3)(setq fileformat 3))
  ((= but 4)(setq fileformat 4))
  ((= but 5)(setq fileformat 5))
  ((= but 6)(setq fileformat 6)) 
)
)

 

 

Can any help me to update pointsin.lsp?

Thanks

0 Likes
Message 19 of 43

Sea-Haven
Mentor
Mentor

Did you run my code ? Works fine for me was going to add as part of dcl what is file type CSV TXT PRS XYZ.

0 Likes
Message 20 of 43

mhy3sx
Enthusiast
Enthusiast

Hi Sea-Haven, I  test your code but a lot of things are missing

 

1) I want to insert 3d points exept block points like pointsin.lsp

2)The file with coordinates have 8 decimal places for X,Y and 3 for Z and your code insert 3 to all

3)The point sin code call the block from a path "c:\\myblock\\point.dwg"

4) Perhaps if not use pointsin code not need radio buttons , just convert the code to support any type of extension file ,but only comma for PENZD something like this

 

(setq fname (getfiled "Select file" "" "" 0))

 

5) And I change this in ths code to work with my block

 

(foreach cogo lst
(setq
POINT (nth 0 cogo)
pt (list (atof (nth 1 cogo))(atof (nth 2 cogo)))
ELEV (nth 3 cogo)
DESC (nth 4 cogo)
)

(vla-insertblock curspace (vlax-3D-point pt) "point" 1 1 1 0)
(setq blk (vlax-ename->vla-object (entlast)))
(setq atts (vlax-invoke blk 'Getattributes))
(vlax-put (nth 0 atts) 'textstring POINT)
(vlax-put (nth 1 atts) 'textstring ELEV)
(vlax-put (nth 2 atts) 'textstring DESC)

)

 

For a first look all this missing for the code. `

 

0 Likes