Creating a default layer sheet

As part of my preparing an AutoCAD drawing for my office’s layering system I managed to insert layers into a drawing from Excel using only scripting.

However the creation of a line and a text on each of the layers, so that users can copy and paste to get the layers etc. into new drawings, needed full AutoCAD and its access to LISP to create these quickly.

The script below is a modified (larger text and longer lines) version of a script, kindly written, from here.

(defun c:lintextfromlayer (/ pt dat ln)
(setq pt (getpoint “\nSelect insertion point: “))
(while (setq dat (tblnext “layer” (null dat)))
(entmake (list ‘(0 . “line”) (cons 10 pt) (cons 11 (mapcar ‘+ pt ‘(5000 0 0))) (cons 8 (setq ln (cdr (assoc 2 dat))))))
(entmake (list ‘(0 . “text”) (cons 10 (mapcar ‘+ pt ‘(5200 -125 0))) ‘(40 . 250) (cons 1 ln) (cons 8 ln)))
(setq pt (mapcar ‘- pt ‘(0 1000 0))))
(princ))

 

Topographical Survey 2D to 3D sketchup

Today I needed to take a 2D survey and create a landscape in Sketchup.

I had the elevation data in the autocad file but it was in metres (I work in mm) and was just text, it had no Z axis data.

Original Survey Points
Original Survey Points

So I needed to get AutoCAD to generate the Z data from the text. However the text was in metres, so first needed to convert it to mm.

Using the Find (and Replace) command I searched the text for the dot or fullstop between the two numbers e.g. 84.51 and replaced it with nothing. So the text became 8451.

All it needed now was the trailing zero. That was easier said than done! I tried several text replacement applications, one was freeware and was completely useless as it required registration and the demo was limited to a small number of items. Others refused to work and some seemed to only work on mtext. Eventually I found one that works a charm, thanks Tharwat!

So now I had a load of text and blocks without any other data. There are a couple of lisp routines I found to assist with adding the Z data. One extracts the data into a text file (I found that I could not manipulate that data as point cloud in AutoCAD so I dismissed it) and the other takes the insertion point of the text (slightly out from the actual survey point but suitable for my needs). They are pntconv.lsp and Txt2pnt.lsp respectively.

I used quickselect to remove all the blocks and was left only with the text.

Then I ran txt2pnt.lsp, and selected all the text, for some reason it did not like that and only create some points. So I ran the lisp several times selecting smaller groups and that worked.

Viewing the point cloud in 3D there were a few stray points that I removed. Also I removed the original text to create a “pure” point cloud.

Now I had a point cloud that I could bring into Sketchup.

Survey Point Cloud
Survey Point Cloud

For this you will need points_cloud_triangulation.rb and the other Ruby file delauney2.rb which the first needs. delauney2.rb is available from Sketchucation. However the file needs renaming to delaunay2.rb when placing into the plugins folder (but works).

Then import the drawing into Sketchup, select all the points (make sure they are exploded) and run the plugin points_cloud_triangulation.rb!

Voila a mesh that can now be smoothed, edited etc!

Sketchup Mesh
Sketchup Mesh

 

Create Hatch

Bizarrely AutoCAD has not (as far as I am aware) created an easy hatch creation method, preferably in a GUI. This is long, long, long outstanding and should have been introduced back in R14 or earlier. If you want to create a hatch, you have to write it out by hand in a text file (there is no automation either), giving the text file a .pat extension.

Apart from the header row for the name and description of the hatch file, the hatch format is like this:

angle, x-origin,y-origin, delta-x,delta-y,dash-1,dash-2

Each line in the text file describes a drawn line, whether this is solid or dashed. All patterns are made from lines that are dashed or continuous and nothing else (a dot a line with a very short or no length). The dash length is variable so you then build up a hatch patten from a set of dashed lines that intersect. 

In order to create say herringbone brick you have the following pattern text:

0, 0,0, 10,10, 30,-10
90, 20,-30, -10,10, 30,-10

This creates a dashed line one way that intersects with one 90 degrees to it and when they repeat a brick pattern occurs. For such a simple shape it is still quite hard to wrap your head around the way they work!

If a complex hatch is required it is expected of the user to somehow translate their drawings from a set of lines into the hatch format. This is of course nigh-on impossible for most users and for a pattern with over one hundred entities will take forever to measure and write out the results, and the 7 step help file isn’t really that helpful and is quite vague.

This is one my major annoyances in AutoCAD that they fiddle with this and that and don’t fix fundamentally missing features like this!

——

If you are thinking, man I cannot do that, don’t worry if you have the full version of AutoCAD (sorry LT guys) you can install a LISP file to do this for you. The awesome guys at Cadalyst posted in one of their tips a hatch creation LISP.

This LISP has two functions, draw and save. Accessed through DRAWHATCH and SAVEHATCH (strangely enough).

The draw hatch command command creates a 1×1 box in drawing units, so for metric in my case this is a 1x1mm box. Tiny!

——

So this is the process I followed to create my hatch.

Firstly, draw your tessellating hatch inside a square, using only line entities. Make sure no curves are present. Then copy this in all directions to make sure the tessellation works! Save this drawing as your template for the hatch.

Secondly, scale your square down to a 1×1 unit square. You can save this as another file if you want. Leave this drawing open (save first, as always before doing anything major).

Thirdly create a new drawing and run DRAWHATCH. This will create a 1×1 unit square with nothing in it. Go back to your open drawing and copy the entities within the square (you can copy the square for ease and delete it after the copy if you want), and paste inside the square drawn in the new drawing by DRAWHATCH.

Fourthly, run SAVEHATCH and select the line objects (polylines won’t work so explode them first) and follow the prompts. A command line window will appear to make things easier.

Fifthly, give it a description and then save it as a file name in a place where you can load them into AutoCAD. Our practice as a server folder for custom hatches.

So that’s it you now have a hatch. One of the problems I encountered with this method is that the created hatch is very small. You will have to enter a large scale factor to correct this.

——

If you are feeling adventurous, you can load the pattern file into Excel and scale the numbers created up to suit. Save out as CSV to get the comma delimited text file back!