Results 1 to 8 of 8

Thread: Program becomes slow after use

  1. #1
    I could stop if I wanted to
    Join Date
    2012-11
    Location
    Brisbane, Australia
    Posts
    239
    Login to Give a bone
    0

    Default Program becomes slow after use

    Hey All

    Hopefully an easy question.
    I have a program that arrays blocks around a drawings and uses Lee Mac's functions to change their properties.
    The program works fine but after placing around 50 blocks it begins to get noticeably slower.
    It remains slow until the drawing is closed and re-opened.

    Is there some sort of file cache reset to simulate the drawings close and open i could build into the program?

    Cheers

  2. #2
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: Program becomes slow after use

    the (gc) function may help.

    Also it sounds like a memory leak.

    Verifying localization of variables.

    I suspect a list is not being set back to nil.

    It is continuing to grow longer every time you run the program.

    I couldn't tell for sure unless I looked at the code and drawing.

    P=
    AutomateCAD

  3. #3
    I could stop if I wanted to
    Join Date
    2012-11
    Location
    Brisbane, Australia
    Posts
    239
    Login to Give a bone
    0

    Default Re: Program becomes slow after use

    Cheers for the fast reply Peter.

    I will have a look through all my variables at my first opportunity.

    If you have an opportunity to have a quick look it would be greatly appreciated.
    I have attached the .lsp file and the block in a zip folder.
    The block needs to sit in the same directory as the .dwg file for it to work.

    The code is kinda long but its just the dialog box creation that chews up space.

  4. #4
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,665
    Login to Give a bone
    0

    Default Re: Program becomes slow after use

    1. Huge amount of variables! Almost none of them are localized. I would even localize all those subfunction names unless you're calling them from another routine.
    2. The dialog box creation chews up space because it's recreated every time the dialog box is shown.
    3. Lot of Command calls.
    Easiest ones to replace:
    Code:
     (command "undo" "begin")
    (command "osmode" "0")
    (command "undo" "end")
    With:
    Code:
     (vla-startundomark (setq acDoc (vla-get-activedocument (vlax-get-acad-object))))
    (setvar 'osmode 0)
    (if	acDoc (vla-endundomark acDoc))

  5. #5
    I could stop if I wanted to
    Join Date
    2012-11
    Location
    Brisbane, Australia
    Posts
    239
    Login to Give a bone
    0

    Default Re: Program becomes slow after use

    Cheers for the feedback Tom, I am self taught and apparently missed some crucial programming techniques.

    Can you give me an example for localized functions to deconstruct or a link to some reference material?

    With the dialog box, I want the program to remain portable in case it needs to move so I made the dialog be created and deleted.
    is this not efficient practice? is there a more efficient way of achieving this outcome without leaving dcl files whenever it is run?

    Thanks for the tip with the vla commands, I really need to research this further, I am not familiar enough to use it on the fly.

    If you can see anything else thing else in my code that I could improve on please let me know.
    I am a solo lisper and get no feedback so my bad practices go unnoticed.

  6. #6
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,665
    Login to Give a bone
    0

    Default Re: Program becomes slow after use

    Quote Originally Posted by LSElite View Post
    Cheers for the feedback Tom, I am self taught and apparently missed some crucial programming techniques.

    Can you give me an example for localized functions to deconstruct or a link to some reference material?
    Just localize the function name like a variable. I added a localized *error* function.
    Code:
    (defun c:spr (/ *error* CheckPrevious txtFile PreviousValue  WritePrevious RoundDown RoundUp setdynpropvalue
    	      fn txt OutputValues SettingList ReadLocalStorage InputValues txtLine LoadInitialValues x1
    	      OutputProperties PropertyList MakeLocalStorage ShowDialog TypeList SubTypeList Switch
    	      dcl_file Local_Storage dcl_id SetBlockProperties SetDefaultBlockProperties SetBlockWorking_1
    	      SetBlockWorking_2 Number1 Total2 Remainder Settings osmode clayer TypeList
    	      SubTypeList PreviousArea PreviousSpacing p1 p2 p3 L1 L2 MaxArea wip1 
    	      SLen LLen SNo SCoverage LCoverage LNo row1 Row2 InsertPoint ClosingMessage)
    
      (defun *error* (msg)
        (if	acDoc
          (vla-endundomark acDoc)
        )
        (cond ((not msg))							; Normal exit
    	  ((member msg '("Function cancelled" "quit / exit abort")))	; <esc> or (quit)
    	  ((princ (strcat "\n** Error: " msg " ** ")))			; Fatal error, display it
        )
        (princ)
      )
    Quote Originally Posted by LSElite View Post
    With the dialog box, I want the program to remain portable in case it needs to move so I made the dialog be created and deleted.
    is this not efficient practice? is there a more efficient way of achieving this outcome without leaving dcl files whenever it is run?
    Guess that fine, haven't tested the code.

    Quote Originally Posted by LSElite View Post
    Thanks for the tip with the vla commands, I really need to research this further, I am not familiar enough to use it on the fly.
    I've got it about half figured out.
    Quote Originally Posted by LSElite View Post
    If you can see anything else thing else in my code that I could improve on please let me know.
    I am a solo lisper and get no feedback so my bad practices go unnoticed.
    I haven't tested any of this, don't know anything about sprinklers. You're going to have to see if it helps.

  7. #7
    I could stop if I wanted to
    Join Date
    2012-11
    Location
    Brisbane, Australia
    Posts
    239
    Login to Give a bone
    0

    Default Re: Program becomes slow after use

    Hey Tom.

    Thanks for the feed back, that is really helpful advice.
    I have localized all my variable however the speed the program places the blocks still gets incrementally slower.

    I have identified the cause of the problem down to the block insertion loop but I cannot find what on earth is causing it.

    Code:
    (while	(< n1 SNo)
    			(setq row1 (+ (nth 0 p3) (+ SInitOff (* SSpacing n1))))
    			(while	(< n2 LNo)
    				(setq	Row2			(- (nth 1 p3) (+ LInitOff (* LSpacing n2)))
    						InsertPoint		(list 
    											row1
    											row2
    											0
    											
    										)
    				)
    				(command "-insert" "THE FILE PATH" InsertPoint "" "" "")
    				(if (/= Settings nil)
    					(progn
    						(SetBlockWorking_1 MaxSpacing SInitOff SSpacing SNo LInitOff LSpacing LNo n1 n2)
    						(SetBlockProperties Settings)
    					)
    					(progn
    						(SetBlockWorking_1 MaxSpacing SInitOff SSpacing SNo LInitOff LSpacing LNo n1 n2)
    						(SetDefaultBlockProperties)
    					)
    				)
    				(setq n2 (+ n2 1))
    			)
    			(setq n1 (+ n1 1))
    			(setq n2 0)
    		)

    Code:
    (defun SetBlockProperties (Settings)
    		(LM:setdynprops (vlax-ename->vla-object (entlast)) 
    			(list	(cons "Type" (nth 0 Settings))
    					(cons "Sub-Type" (nth 1 Settings))
    					(cons "Working" (nth 2 Settings))
    					(cons "PhaseTag" (nth 3 Settings))
    			)
    		)
    	)
    	(defun SetDefaultBlockProperties ()
    		(LM:setdynprops (vlax-ename->vla-object (entlast)) 
    			(list	(cons "Type" "Recessed")
    					(cons "Sub-Type" "(none)")
    					(cons "PhaseTag" "OFF")
    					(cons "Working" "OFF")
    			)
    		)
    	)
    	(defun SetBlockWorking_1 (MaxSpacing SInitOff SSpacing SNo LInitOff LSpacing LNo n1 n2)
    		(LM:setdynprops (vlax-ename->vla-object (entlast))
    			(list	(cons "MaximumSpacing" MaxSpacing)
    					(if (= n1 (- SNo 1))
    						(cons "XRight" SInitOff)
    						(cons "XRight" (/ SSpacing 2))
    					)
    					(if (= n1 0)
    						(cons "XLeft" SInitOff)
    						(cons "XLeft" (/ SSpacing 2))
    					)
    					(if (= n2 0)
    						(cons "YTop" LInitOff)
    						(cons "YTop" (/ LSpacing 2))
    					)
    					(if (= n2 (- LNo 1))
    						(cons "YBottom" LInitOff)
    						(cons "YBottom" (/ LSpacing 2))
    					)
    			)
    		)
    	)

  8. #8
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,665
    Login to Give a bone
    0

    Default Re: Program becomes slow after use

    You only need to insert the blocks once with a file path. At the start of the routine use tblsearch to see if it's in the drawing already and insert it if needed. Then use vla-insertblock for all the insertions. Lots of examples for each lisp function online.

Similar Threads

  1. 2013: ACAD 2013 SP2 Shift-Deselect works, but super slow. Issuing commands is slow.
    By Professor Lavahot in forum AutoCAD General
    Replies: 11
    Last Post: 2013-08-05, 03:41 PM
  2. Open GL not available and program running slow?
    By patricks in forum Revit - Platform
    Replies: 0
    Last Post: 2008-02-21, 03:05 PM
  3. Export model to Sketchup - program runs very slow
    By dg in forum Revit Architecture - General
    Replies: 5
    Last Post: 2004-11-04, 08:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •