labmonkey Posted June 22, 2012 Author Posted June 22, 2012 Mircea, you're a god send. Turning off the osnap (actually it was the 3D snap in my case) has solved all those little problems. Quote
Blackfish Posted June 22, 2012 Posted June 22, 2012 I now have to decide the best way to generate the script, i.e. how to get the coordinates out of the existing *.cel file. Originally I was going to write a macro in excel, but there may be an easier approach. For your information, the *.cel file has lines like SD 600000.000000; DZ TL-0.079289,-0.229289; TL-0.079289,-0.200000; TL0.020711,-0.200000; TL0.020711,-0.229289; where the numbers in the second line are coordinates for a pline. I think it will be relatively straightforward to do extract the useful information, but I'm not sure of the most efficient way of doing it right now. I will try in excel and see where that gets me. The number in the first line is related to the colour I'd want for the lines/bhatch, but that's beyond what I want to do now. You can you wisely a simple Notepad and replace as follow in the respective order: '; TD' with ' ' (blank space) 'DZ TL' with '_PLINE' ';' with ' _CLOSE _CHPROP _L _C 3 _HATCH _P _S _L _CHPROP _L _C 3 ' and whatever you want to do with the first line, you said something about color, don't you? However you have to adjust the script with colors, numbering of polylines (especially the last replacement) etc., but the main part will be done. Quote
labmonkey Posted June 22, 2012 Author Posted June 22, 2012 Hello Blackfish, you're right, essentially it's a find and replace problem. However, the added difficulty is the colour. An example excerpt of the original file is Many lines of nonsense SD 500000.000000; DL TL-0.096860,0.032583; TL-0.056082,0.032583; SD 600000.000000; DS TL-0.069138,-0.014067; TL-0.015304,0.014531; SD 700000.000000; DT TL0.046400,-0.049277; TL0.016532,-0.033012; TL0.061988,-0.033012; DZ TL0.016532,-0.033012; TL0.021128,-0.023897; TL0.070724,-0.023897; TL0.061988,-0.033012; DZ TL0.021128,-0.023897; TL0.028157,-0.009956; TL0.055287,-0.009956; TL0.070724,-0.023897; DT TL0.028157,-0.009956; TL0.046579,-0.002091; TL0.055287,-0.009956; Many more lines of nonsense. The lines beginning with DL, DT, and DZ are the coordinates I want to map out. The lines beginning SD are the 'dose', which is what I'd like to colour. So, in this case, SD=500000, 600000, and 700000 are the first, second and third doses respectively. So I'd like to colour code them red, blue and green respectively. In a more complicated example they wouldn't be in the correct order, so it's not a simple case of incrementing the colour each time there is a new "SD". For this example, I would like to end up with a script like this _LINE -96.860,32.583 56.082,32.583 _CHPROP _L _C 1 _HATCH _P _S _L _CHPROP _L _C 1 _RECTANGLE -69.138,-14.067 -15.304,14.531 _CHPROP _L _C 2 _HATCH _P _S _L _CHPROP _L _C 2 _PLINE 46.4,-49.277 16.532,-33.012 61.988,-33.012 _CLOSE _CHPROP _L _C 3 _HATCH _P _S _L _CHPROP _L _C 3 _PLINE 16.532,-33.012 21.128,-23.897 70.724,-23.897 61.988,-33.012 _CLOSE _CHPROP _L _C 3 _HATCH _P _S _L _CHPROP _L _C 3 _PLINE 21.128,-23.897 28.157,-9.956 55.287,-9.956 70.724,-23.897 _CLOSE _CHPROP _L _C 3 _HATCH _P _S _L _CHPROP _L _C 3 _PLINE 28.157,-9.956 46.579,-2.091 55.287,-9.956 _CLOSE _CHPROP _L _C 3 _HATCH _P _S _L _CHPROP _L _C 3 with a legend at the end like this _COLOR 1 _MTEXT 100,42 _H 5 100,48 SD=500000 _COLOR 2 _MTEXT 100,36 _H 5 100,42 SD=600000 _COLOR 3 _MTEXT 100,30 _H 5 100,36 SD=700000 I've attached a file to give you an idea of a more realistic original file. There's about 7000 lines of redundant code before the real stuff starts, but it's quite easy to find the real stuff because that begins with the first occurrence of "SD". I suspect I can load into excel and use a macro to sort them into SD order and find and replace the relevant terms. I am not sure that's the most efficient way of doing it, but it's probably the easiest way for me to do it. test.txt Quote
Blackfish Posted June 25, 2012 Posted June 25, 2012 labmonkey, how's things? If you can sort lines in any program 'by desired color' than you can apply 'find/replace' selectively to each color and change the end (e.g. '_C 3') to proper color/text. You don't have to multiply data by 10 in excel (to omit one step), you can leave it at the end in AutoCAD, when all is drawn, just multiply by 10 with 0,0 as a reference center. There is no need to use different entities like line, rectangle or polyline, just use POLYLINE; it will work the same way and your replacement will be much much easier. Quote
labmonkey Posted June 28, 2012 Author Posted June 28, 2012 Hello Blackfish, thanks for asking and for your suggestions. I've got a VBA macro doing most of what I need it to, so I am almost there. An example of my resulting script is here _LAYER _N celcheck _S celcheck ; insert a new layer, name it celcheck, make it current layer _PLINE 1323.715,2262.742 1997.465,2262.742 _CLOSE _CHPROP _L _C 1 _HATCH _P _S _L _CHPROP _L _C 1 ; insert a _PLINE _RECTANGLE 1308.285,1851.591 1874.030,2026.330 _CHPROP _L _C 1 _HATCH _P _S _L _CHPROP _L _C 1 ; insert a _RECTANGLE _PLINE 1261.997,1548.367 1395.719,1738.524 1493.438,1435.301 1308.285,1435.301 _CLOSE _CHPROP _L _C 1 _HATCH _P _S _L _CHPROP _L _C 1 ; insert a _PLINE _PLINE 1735.165,1584.343 1946.034,1702.549 1946.034,1460.998 1832.885,1460.998 _CLOSE _CHPROP _L _C 1 _HATCH _P _S _L _CHPROP _L _C 1 _PLINE 1961.463,1224.586 2120.900,1620.319 _CLOSE _CHPROP _L _C 1 _HATCH _P _S _L _CHPROP _L _C 1 _PLINE 2120.900,1620.319 2285.480,1327.373 _CLOSE _CHPROP _L _C 1 _HATCH _P _S _L _CHPROP _L _C 1 _PLINE 2285.480,1327.373 2187.761,1168.052 _CLOSE _CHPROP _L _C 1 _HATCH _P _S _L _CHPROP _L _C 1 _LAYER _N doses _S doses ; insert a new layer, name it doses, make it current layer ; next, make the legend _COLOR 1 _MTEXT 500,2000 _H 40 500,2500 Red=1.0 ; insert with font size = 40 at coordinates 500,2500 the text "Red=1.0" _COLOR 2 _MTEXT 500,1950 _H 40 500,2450 Yellow=2.0 _COLOR 3 _MTEXT 500,1900 _H 40 500,2400 Green=3.0 _COLOR 4 _MTEXT 500,1850 _H 40 500,2350 Cyan=4.0 _COLOR 5 _MTEXT 500,1800 _H 40 500,2300 Blue=5.0 _COLOR 6 _MTEXT 500,1750 _H 40 500,2250 Magenta=6.0 _COLOR 7 _MTEXT 500,1700 _H 40 500,2200 White=7.0 _COLOR 8 _MTEXT 500,1650 _H 40 500,2150 Other=8.0 ; next, zoom out to the extents _ZOOM _E I would be interested to know if there's anything terrible about that code, or anything I can write more elegantly (particularly the latter half). There's one part I am struggling to think of the best way to do. The latter half of that code generates a legend. It's a bit tricky (but far from impossible) to get the VBA macro to work out exactly where to put the legend in a reasonable position, so I was wondering if you can insert a _MTEXT at coordinates as a percentage of the current screen instead of real x, y values. Then I wouldn't need to worry, I could just put them at fixed percentages, so it's always drawn in the top left corner for example. Alternatively, which I don't think is possible, but I'll ask anyway... can you have a layer whose view is completely independent of other windows? That is, if I have layer one zoomed out so I can see 500,500 to 1000,1000, can I have another layer on top which is zoomed in so I can see 0,0 to 1,1? That way, whatever I did to the first layer, the view of the second layer is never changed. Not sure if I made that clear, but hopefully you understand what I mean. Quote
MSasu Posted June 28, 2012 Posted June 28, 2012 I would be interested to know if there's anything terrible about that code, or anything I can write more elegantly What really mater in most cases is that your solution works and gets you the results you were looking for; the aesthetics come later. can you have a layer whose view is completely independent of other windows? That is, if I have layer one zoomed out so I can see 500,500 to 1000,1000, can I have another layer on top which is zoomed in so I can see 0,0 to 1,1? That way, whatever I did to the first layer, the view of the second layer is never changed. Not sure if I made that clear, but hopefully you understand what I mean. As far as I know, you cannot control independently the zoom factor on layers in the same view. One workaround that I can suggest if to create two overlapped viewports and freeze one of the said layers in first viewport, respectively the other layer in second viewport. Keep above the viewport with layer you want to play in with zoom factor. Although I'm not sure if this will not become very confusing. Quote
labmonkey Posted June 28, 2012 Author Posted June 28, 2012 Thanks Mircea, viewport could well be the way to go. I haven't used them before, so will do some reading up. If it does what I think it does, it will be just the job. Quote
MSasu Posted June 28, 2012 Posted June 28, 2012 There's one part I am struggling to think of the best way to do. The latter half of that code generates a legend. It's a bit tricky (but far from impossible) to get the VBA macro to work out exactly where to put the legend in a reasonable position, so I was wondering if you can insert a _MTEXT at coordinates as a percentage of the current screen instead of real x, y values. Then I wouldn't need to worry, I could just put them at fixed percentages, so it's always drawn in the top left corner for example. Please check if this previous discussion isn't useful for your case. Quote
Blackfish Posted June 28, 2012 Posted June 28, 2012 There's one part I am struggling to think of the best way to do. The latter half of that code generates a legend... Why not to build a BLOCK of legend once and copy/paste into each drawing? Quote
labmonkey Posted July 11, 2012 Author Posted July 11, 2012 Hi, I just want to thank everybody again for their help. It is greatly appreciated. I am still completing the program to automatically create the script file, but I think I can do everything I want with regards to the AutoCAD script itself. In case anybody wants to do something similar to me, a word of advice. The script runs much, much faster if you group all the colours together. Changing the colour with each line massively increases the time to complete the script. For example, I had about 10,000 _PLINE commands, which took over an hour to draw with commands like this _PLINE 1323.715,2262.742 1997.465,2262.742 _CLOSE _CHPROP _L _C 1 _HATCH _P _S _L _CHPROP _L _C 1 , but just a few minutes (or less) with commands like this _PLINE 1323.715,2262.742 1997.465,2262.742 _CLOSE _HATCH _S _L Quote
labmonkey Posted August 16, 2012 Author Posted August 16, 2012 Hello again. As I said in my last message, I've basically got it now, however, I was wondering if anybody has any suggestion how to speed up the script even further. At the moment the script looks something like: _LAYER _N cel _S cel _CETRANSPARENCY 50 _CECOLOR 1 _RECTANGLE 1751.177,7033.964 1752.667,7033.664 _HATCH _S _L _RECTANGLE 1752.737,7033.964 1754.227,7033.664 _HATCH _S _L _RECTANGLE 1751.177,7032.964 1752.667,7032.664 _HATCH _S _L _RECTANGLE 1752.737,7032.964 1754.227,7032.664 _HATCH _S _L _CECOLOR 2 _RECTANGLE 1752.802,7034.034 1752.602,7038.084 _HATCH _S _L _RECTANGLE 1752.802,7028.544 1752.602,7032.594 _HATCH _S _L .......................... Which takes a long time if there's many thousands of rectangles. Clearly, this just goes through the rectangles one by one drawing them in sequence. I can often see this happening live on the screen, so I was wondering if I can make it faster by somehow stopping the screen refreshing until it's finished the script. Can I do that, and would it make a difference? Also, as you can see, at the moment I am using the _HATCH command with each individual rectangle. Could it be faster to select them all at the end and HATCH them all together? How could I do that? It would probably have to be more complicated than that because I'd want these rectangles to (sometimes) be HATCHed with different colours (that's what the _CECOLOR command is for), however, I could get round that by creating a new layer for each individual colour. Thanks in advance. Quote
fuccaro Posted August 17, 2012 Posted August 17, 2012 If somebody is wondering: labmonkey is referring to these posts: http://www.cadtutor.net/forum/showthread.php?70218-Importing-polygon-from-a-csv-file&p=482402#post482402 For so many rectangles, if speed is a concern, I would try a Lisp approach. You should draw the rectangles with Entmake (not with command "rectangle..."). Also put them from start on the right layer by entering the right code in that Entmake, and put the Hatch on the same layer as the rectangle is. I admit that is more complicated as the script you developed, but you have to pay a price if you wish to progress. Quote
labmonkey Posted August 18, 2012 Author Posted August 18, 2012 Thanks fuccaro. It turns out that it's faster than I expected. Using the script method I could draw 100,000 lines in about 15 minutes. In most cases I'll only need a maximum of a few hundred objects (lines, rectangles etc.) so 99% of the time it's not an issue. I was just wondering if there was a simple way to speed it up for the other 1%. The simpler I keep it the better because it will be used by non-experts, so typing the word SCRIPT is ideal. Thanks again to everybody in this thread. If somebody does think of a way to speed the script up I would appreciate it, but it looks like it's not such a big issue any more. Quote
MSasu Posted August 18, 2012 Posted August 18, 2012 I’m not sure if there something to be improved to your script; it look well optimized to me. Don’t forget that the script technology is emulating user’s inputs on prompter, so is to expect to be time consuming since it requires printing on prompter and draw on screen. I will second @fuccaro observation that an AutoLISP routine using ENTMAKE will improve the speed, but this require for you to start learning this language. It may be difficult at beginning, but I’m sure you will benefit from it on long term. Quote
labmonkey Posted August 19, 2012 Author Posted August 19, 2012 Thanks MSasu, I think for now the script is the way to go. It's a pretty simple language to understand, which is useful so my colleagues can follow what the script is doing without having to study the language. If in the future I really need to speed things up I will look at LISP routines. Quote
fuccaro Posted August 20, 2012 Posted August 20, 2012 Thanks MSasu, I think for now the script is the way to go. It's a pretty simple language to understand, which is useful so my colleagues can follow what the script is doing without having to study the language. I don't try to push you in the Lisp dirrection, just a small observation: once you have a program loaded, the user just enters a name in the command line to start it. Quote
Humayoun Posted March 30, 2022 Posted March 30, 2022 On 6/20/2012 at 1:32 PM, MSasu said: _RECTANGLE 0,0,0 10,5 _HATCH _P _S _L _CHPROP _L _C 5 _RECTANGLE 15,9,0 20,17 _HATCH _P _S _L _CHPROP _L _C 2 _RECTANGLE -15,-9,0 -20,-17 _HATCH _P _S _L _CHPROP _L _C 7 _ZOOM _E ;end of script Quote
Recommended Posts
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.