Jump to content

Intelligent joining, of lines


M76

Recommended Posts

I've updated the code, its much faster and relaible now.

 

(map_clean elem 0 32 0.00 T) ; dissolve pseudo
               (setq done T)
               (setq hlof nil lhlof nil)
               (while done  ; loop until all the lines have been processed
                   (command "_zoom" "_e" "_redraw")
                   (setq lof (ssget "_X" (list (cons 0 "LWPOLYLINE") (cons 8 elem)))) ; select all polylines on the object layer
                   (if lof
                       (progn
                           (setq hlof (sslength lof))
                           (princ (strcat "\rHátralevő: " (itoa hlof)))
                           (if (= hlof lhlof) (setq done nil))
                           (setq lhlof hlof)
                           (setq ch T)
                           (while (and done (< 0 hlof))
                               (setq entx (ssname lof 0))
                               (setq lof (ssdel entx lof))
                               (make-vert-list entx)                                    ; creates a list of points from the polyline
                               (setq line1 vert-list)
                               (setq pstart (car line1))                                ; get the first and second points
                               (setq pend (cadr line1))
                               (command "_zoom" "_c" pstart 50)
                               (setq sp1 (polar pstart (/ pi 4) 0.1))
                               (setq sp2 (polar pstart (* 5 (/ pi 4)) 0.1))
                               (command "_change" entx "" "_p" "_la" "_lay" "")        ; change the examined line's layer so the next selection won't find it again
                               (setq lef (ssget "_C" sp1 sp2 (list (cons 0 "LWPOLYLINE") (cons 8 elem))))
                               (command "_change" entx "" "_p" "_la" elem "")            ; put it back to the original layer
                               (if (and lef (= 2 (sslength lef)))                        ; if there are two lines found start comparing angles
                                   (progn
                                       (setq enty (ssname lef 0))
                                       (setq entz (ssname lef 1))
                                       (if lof (setq lof (ssdel entz lof)))
                                       (if lof (setq lof (ssdel enty lof)))
                                       (make-vert-list enty)
                                       (setq line2 vert-list)
                                       (make-vert-list entz)
                                       (setq line3 vert-list)
                                       (if (< (distance (car line2) pstart) (distance (car (reverse line2)) pstart))    ; find which end of the found lines are actually connected to the first line end
                                           (setq pstarty (car line2) pendy (cadr line2))
                                           (setq pstarty (car (reverse line2)) pendy (cadr (reverse line2)))
                                       )
                                       (if (< (distance (car line3) pstart) (distance (car (reverse line3)) pstart))    
                                           (setq pstartz (car line3) pendz (cadr line3))
                                           (setq pstartz (car (reverse line3)) pendz (cadr (reverse line3)))
                                       )
                                       (if (and (< (abs (- (angle pend pstart) (angle pstarty pendy))) (abs (- (angle pend pstart) (angle pstartz pendz)))) (< (abs (- (angle pend pstart) (angle pstarty pendy))) (abs (- (angle pendy pstarty) (angle pstartz pendz))))) ; compare the angle of the last/first segments
                                           (command "_join" entx enty "")
                                           (if (and (< (abs (- (angle pend pstart) (angle pstartz pendz))) (abs (- (angle pend pstart) (angle pstarty pendy)))) (< (abs (- (angle pend pstart) (angle pstartz pendz))) (abs (- (angle pendy pstarty) (angle pstartz pendz)))))         ; and join with the one that has less difference
                                               (command "_join" entx entz "")
                                               (command "_join" enty entz "")
                                           )
                                       )
                                       (setq ch nil)                                                                                                    ; set the changed flag so it will end the loop and get the selection set again where the two lines are joined
                                       
                                   )
                                   (progn                                                                ;do the same at the  end of the polyline, if nothing was found at the beginning
                                       (setq pstart (car (reverse line1)))
                                       (setq pend (cadr (reverse line1)))
                                       (command "_zoom" "_c" pstart 50)
                                       (setq sp1 (polar pstart (/ pi 4) 0.1))
                                       (setq sp2 (polar pstart (* 5 (/ pi 4)) 0.1))
                                       (command "_change" entx "" "_p" "_la" "_lay" "")
                                       (setq lef (ssget "_C" sp1 sp2 (list (cons 0 "LWPOLYLINE") (cons 8 elem))))
                                       (command "_change" entx "" "_p" "_la" elem "")
                                       (if (and lef (= 2 (sslength lef)))
                                           (progn
                                               (setq enty (ssname lef 0))
                                               (setq entz (ssname lef 1))
                                               (if lof (setq lof (ssdel entz lof)))
                                               (if lof (setq lof (ssdel enty lof)))
                                               (make-vert-list enty)
                                               (setq line2 vert-list)
                                               (make-vert-list entz)
                                               (setq line3 vert-list)
                                               (if (< (distance (car line2) pstart) (distance (car (reverse line2)) pstart))
                                                   (setq pstarty (car line2) pendy (cadr line2))
                                                   (setq pstarty (car (reverse line2)) pendy (cadr (reverse line2)))
                                               )
                                               (if (< (distance (car line3) pstart) (distance (car (reverse line3)) pstart))
                                                   (setq pstartz (car line3) pendz (cadr line3))
                                                   (setq pstartz (car (reverse line3)) pendz (cadr (reverse line3)))
                                               )
                                               (if (and (< (abs (- (angle pend pstart) (angle pstarty pendy))) (abs (- (angle pend pstart) (angle pstartz pendz)))) (< (abs (- (angle pend pstart) (angle pstarty pendy))) (abs (- (angle pendy pstarty) (angle pstartz pendz))))) ; compare the angle of the last/first segments
                                                   (command "_join" entx enty "")
                                                       (if (and (< (abs (- (angle pend pstart) (angle pstartz pendz))) (abs (- (angle pend pstart) (angle pstarty pendy)))) (< (abs (- (angle pend pstart) (angle pstartz pendz))) (abs (- (angle pendy pstarty) (angle pstartz pendz)))))         ; and join with the one that has less difference
                                                           (command "_join" entx entz "")
                                                           (command "_join" enty entz "")
                                                       )
                                               )
                                               (setq ch nil)
                                           )
                                       )
                                   )
                               )
                               
                               (if lof (setq hlof (sslength lof)) (setq hlof 0))
                               
                           )
                       )
                       (setq done nil) ; if there are no suitable objects on the object layer end the loop
                   )
                   
               )

Link to comment
Share on other sites

  • Replies 33
  • Created
  • Last Reply

Top Posters In This Topic

  • M76

    17

  • ReMark

    6

  • fart_plume

    5

  • Tiger

    3

Top Posters In This Topic

Posted Images

How much faster?

 

What is the largest drawing file you have used this routine on so far?

 

Have there been any further "snags"? If so, where does the program have the most difficulty?

Link to comment
Share on other sites

The problems are mostly related to irregularities in the drawings.

 

Its a part of a more complex process, as I mentioned before the biggest drawings I used have about 150.000 objects, but only about 10.000 of those take part in this joining.

 

The most time consuming operation in the whole process is now the unioning of regions, I'm mergeing them one-by-one to avoid running out of memory. If I start an union on 10.000 regions autocad can allocate huge amounts of memory, and also I have no way of displaying progress then, the process just starts, and I have no response for ten minutes.

 

Going one by one is ok for about 5000 regions, but if there are more than that it gets ridiculously slow, I don't know why since I'm still joining two at a time only.

 

If there were an alternative to using the "union" command, that could speed up things probably.

Link to comment
Share on other sites

What are the specs of the computer you're running this on? Sounds like you need to beef it up.

 

I don't know of any substitute for the Union command that would speed things up.

Link to comment
Share on other sites

Autocad is very slow in itself, the computer spec doesn't have much effect on it, especially since its only capable of using one cpu core. The computer is a Core2Duo 2.8Ghz with 4GB ram.

 

I've tried to change union to vla-boolean, but it seems even slower this way.

Link to comment
Share on other sites

After doing some reading in other sections you might try using the WHIPTHREAD command and setting the variable to 3, this will allow autocad to use more than one core for regens and redraws. Also You can do a CTRL ALT Del bring up the task manager, click processes tab find the autocad processes and right click and click process affinity to set which core of the cpu you want the each process to use. you can view which core is taking most of the load by clicking the performance tab while your processing a drawing so you know which core to place more work on to balance the load on your system.

 

Also while your in the processes tab you can see what processes are eating memory up, if they are not your cad then if you don't need them shut the associated program down, a lot of brand name pc's have alot of TSR's running(terminate and stay resident) that will stay in memory unless you actually go in and shut them all the way down. One more thing is you need to go to control panel - system-advanced-performance-advanced-page file-change then set your page file to twice that of what your memory is in both windows and click. in your case if your running a 64 bit os it would be 4092. This will improve your page file swapping and help keep your had from getting all fragmented up which will also cause your system to slow down.

Link to comment
Share on other sites

Thanks I've no problems with the memory running out, so that's not an issue now. Speed is.

 

I was able to quicken the unioning by about 100 times. The method is simple, I try to keep the objects small and therefore less complex for as long as possible. If I have say 10.000 regions to union. I merge the 1st with the 10.000th the 2nd with the 9999th and so on. Since the small parts are not complex this goes very quickly when I get to the middle I start again, this time with the remaining 5000 objects. It only starts to slow down when I'm down to about 6-8 regions.

Link to comment
Share on other sites

Some of the things I suggested also have the effect of freeing CPU cycles which does increase the speed of programs such as Autocad, also the whipthread command by allowing Autocad to run across both cores at the same time doubling your processing power and swap file setting allows for faster page switching, another system tweak to increase speed by unclogging a bottle neck.

 

To put it simply I admire your work on increasing the speed of your command, however system tweaks such as these will also increase the efficiency of your workstation system wide. Things like running instant messaging programs, weather programs like weather bug are just a waste of cpu time.

 

Any way I was just trying to help by getting rid of some of the know bottle necks in PC workstations.

Link to comment
Share on other sites

I've tried whipthread variable but it doesn't seem to have much effect.

 

Tell me why is it that if autocad is in focus, it only updates the screen every 5-10 seconds. But if I set the focus to another window it displays every screen update real time, which slows down the processing. That hinders the possibility to do something else during processing since as soon as autocad looses focus, the processing speed drops by two thirds at least even if its minimized.

 

It would be greet to control how the display refresh occurs. Or it would be even better if I could turn it off completely, because there is no need for it. But I suspect ssget won't work then, since when I'm not zoomed to the exact location where I want to select something ssget will return nil.

 

Also if some processing takes a long time example the unioning of two complex regions the whole autocad window will turn blank and unresponsive.

Link to comment
Share on other sites

What video card do you have in your system? if it is an older cad card or gaming card it won't have the processing required to do real time updates. A lot of times (more often than not) it's not the cpu power that is lacking but the video card, which it sounds like in your case due to the screen going blank and unresponsive. The video card frame rate has dropped below what is necessary to continuously update the monitor.

 

Case in point my video card is not a cad card but a now third tier gaming card(I could use Rivatuner to turn on all the cad features, but haven't done so yet.) and with 10,000 polylines you can see it slow down and redraw every line as I zoom, not fluid at all. With the number of polylines your dealing with I would say it prolly not so much the cpu as it is the video card needs upgrading to a better cad card.

 

As for the processing faster when you shift focus is due to the video card handing the data over to the cpu to process rather than the GPU(graphics processing unit on the video card) since it not having to constantly update the non focused portion, just where you are focused.

Link to comment
Share on other sites

The video processing is Faster Not the processing of your line joining. Your video processing increases due to the hand off to the CPU of the non focused data(where it is joining lines). Something your have to remember Video cards have more processing pipelines than a cpu on an order of 25:1 up to 75:1 differnece in number of pipelines. Your CPU IF it is a Dual core prior to I7 series to won't see much gains with whipthread, it also depends on what version of Autocad your running, I'm sure they have been working on thread number scalability(how many cores the processing can occur on, since they have Hexacore CPU's coming out very soon.)

 

If your data sets are so large have you considered getting a second identical video card installing, and setting up SLI or Crossfire to increase it's processing speed?

Link to comment
Share on other sites

You're speaking about something completely different and irrevelant. Buying an i7 cpu with 6 cores won't make any difference since autocad cannot even utilize 2 cores or cpus.

 

I've tried 2007 and 2010, there is not much difference, maybe 2010 is even slower than 2007, so there were no multithread optimizations. There is no multithreading at all.

 

You're saying that the video card is slow that's the problem, if that were the case why is it that autocad uses ONE cpu core at 100% utilization, if the vga were the bottleneck wouldn't there be spikes in the processing when the cpu waits for the gpu to finish?

Link to comment
Share on other sites

No, because that is what your page file does is take the data the Cpu is going to process and swap it out for what it already has processed. The GPU is bottle necking on the data it is receiving, to calculate all the changes being made to the render frame.

 

As an Example right now there is only one game I know of (never played it), That No system since it came out is able to run it at full video render settings to to the sheer amount of data that the processor and GPU have to process just for one frame(it requires a minimum of 30 frames /sec to render action so it looks some what fluid), so not only is your GPU pulling the data from the CPU it also has to process that information to the monitor. So the two choices for getting faster video is 1) buy a better card or 2) get a second identical one and link them together so the slave card helps the primary process the video data. (I just Started My Acad with the Task manager up it spiked all four cores and was running 17 threads just for Acad.exe)

 

Another thing that might help is if your running a 32 bit os is to move on up to 64 bit, the wider bandwidth should free up some of the processor time even if your still run Autocad 32 on it(Another plus is the 64 bit os will let you have access all memory installed, if your running 32 Windows you'll have between 3.2 and 3.5 GB's of memory available to you, in a 64 bit Os you can install as much as your system can hold and be able to use it. And yes having tons of memory helps because it does have to Read and write from the HD page file as much, this alone can bottle neck a system.)

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