Tag Archives: AutoCAD

Interactive AutoCAD in Website

31 Oct

I have previously shown how to put a drawing in a website using DWF and OpenLayers. This time I will show how to use an image map created by Qgis.

Save your drawing as a DXF. I am interested in room polygons so here is my drawing:

Bring this drawing in to Qgis as a polygon using the dxf2shp converter plugin.

You now have a shapefile:

Open the editor and add a column for room names. I also added a column for URLs which will be used for a popup later.

Now we can export the drawing to an image map based website using the HTML Image Map Plugin.

Configure the webpage using the options provided. I am using the URL field for “href attr” option. This will make it a link that can be clicked. I will ignore the onlclick, and stick with a hover.

 

 

 

I opened up the HTML code and added a title, my face, and put the hover <DIV> at the bottom of the page. When you hover over a room, you will see the type of room displayed on the bottom of the page and as a tooltip. If you click a room, you will be taken to a website. You can fully customize this website. And I suggest you do.

Here are all my files in a ZIP if you want to play with the webpage or see my awesome DXF. The File is named “Files.DOC” I had to do this to upload them. Rename the file to “Files.ZIP” and it will work fine. FYI – this is a cool trick to hide files. Windows reads the extension and makes it look like the extension. But it is really whatever you created originally.

Shapefiles to AutoCAD DWG Using Python

29 Oct

This will be my last post on this topic. I will show how to create a DWG from a shapefile using python. This requires AutoCAD – as my other methods did not.  You will also need python, shapefile.py and pyautocad – and it’s dependency.

With AutoCAD open I run this code:

from pyautocad import Autocad, APoint
import shapefile

openshape = shapefile.Reader(“C:\Documents and Settings\user\Desktop\surveyShapefile”)
shpPoints = openshape.shapes()

acad = Autocad()

def readShapefile():
x = 0
while (x <= 100):
xy= shpPoints[x].points[0]
p1 = APoint(xy[0], xy[1])
acad.model.AddCircle(p1, .0001)
print ‘Reading Record: ‘+ str(x)
x=x+1

else:
print ‘Complete…’

readShapefile()

The result is my Survey in AutoCAD as points with the correct coordinates – coordinates from the GIS  in this case are WGS84.

We can modify the script by adding: acad.model.AddLine(p1, p2). This will convert a line shapefile to autoCAD. The code:

from pyautocad import Autocad, APoint
import shapefile

openshape = shapefile.Reader(“C:\Documents and Settings\user\Desktop\majorstreets”)
shpPoints = openshape.shapes()

acad = Autocad()

def readShapefile():
x = 0
while (x <= 5):
xy1 = shpPoints[x].points[0]
p1 = APoint(xy1[0], xy1[1])
xy2 = shpPoints[x].points[1]
p2= APoint(xy2[0], xy2[1])
acad.model.AddLine(p1, p2)
print ‘Reading Record: ‘+ str(x)
x=x+1

else:
print ‘Complete…’

readShapefile()

 

And the results:

 

You can use AutoLISP or probably .NET but Python is free and easy to learn.  Well, now you know another way to load shapefiles in to AutoCAD. With this in CAD, you can save it as a DWG and go straight to Revit.

And it does 3D:

from pyautocad import Autocad, APoint
acad = Autocad()

p1= APoint(10,10,10)
acad.model.AddCircle(p1, 10)

Let me state again that this code is sloppy – but functional. It is for demonstration purposes, so if you use it, clean it up and make the loops better.

Shapefiles to Revit or AutoCAD: Using Python to write DXF

29 Oct

I have shown how to get shapefiles in Revit Using Qgis, and mentioned how to do the same with AutoDesk Civil and ESRI ArcMap. But I have another way – Python.

I have written a program that will read in a point shapefile and convert it to DXF. If you have a survey point shapefile, run my script and you will have a survey point DXF. I would love to write to DWG but AutoDesk charges for that library – proprietary file formats and all….

I always start my programs with baby steps – no matter how simple the problem. So let me walk through how this code developed.

First, I drew a DXF from Python manually – lines then points.

Lines:

from dxfwrite import DXFEngine as dxf
drawing = dxf.drawing(‘testLines.dxf’)
drawing.add_layer(‘SURVEY’)
drawing.add(dxf.line((0, 0), (1, 0), color=7, layer=’SURVEY’))
drawing.add(dxf.line((2, 0), (3, 0), color=5, layer=’SURVEY’))
drawing.save()

Points:

from dxfwrite import DXFEngine as dxf
drawing = dxf.drawing(‘DXF.dxf’)
drawing.add_layer(‘SURVEY’)
points = dxf.point((1, 5), color=7, layer=’SURVEY’)

drawing.add(points)

drawing.save()

Then I wanted to try from an Excel file since this is easy practice for passing points to the DXFEngine:

from dxfwrite import DXFEngine as dxf
import xlrd
book = xlrd.open_workbook(“readdxf.xls”)
sh = book.sheet_by_index(0)
drawing = dxf.drawing(‘DXFFromExcel.dxf’)
drawing.add_layer(‘SURVEY’)

def readRow():
for rownum in range(sh.nrows):
rows=sh.row_values(rownum)
points = dxf.point((sh.cell_value(rowx=rownum, colx=0), sh.cell_value(rowx=rownum, colx=1)), color=7, layer=’SURVEY’)
drawing.add(points)
print ‘Reading Record: ‘+ str(rownum)

else:
print ‘Complete…’

readRow()
drawing.save()

Lastly, I read from a shapefile:

from dxfwrite import DXFEngine as dxf
import shapefile
drawing = dxf.drawing(‘DXFFromSHP.dxf’)
drawing.add_layer(‘SURVEY’)
openshape = shapefile.Reader(“C:\Documents and Settings\user\Desktop\surveyShapefile”)
shpPoints = openshape.shapes()

def readShapefile():
x = 0
while (x <= 100):
points = dxf.point((shpPoints[x].points[0]), color=7, layer=’SURVEY’)
drawing.add(points)
print ‘Reading Record: ‘+ str(x)
x=x+1

else:
print ‘Complete…’

readShapefile()
drawing.save()

The loop is lame and only grabs the first 100 points. I just wanted to quickly show how to do it. Modify this anyway you want – you will need to add your file names anyway.

This file can also be modified to read and write polyline shapefiles too.

You will need to install Python, shapefile.py and DXFwrite.py for this to work. I have tested the DXF files in Qgis, but not in AutoCAD or Revit.

OpenLayers and AutoCAD: OpenLayers.Layer.Image

20 Jun

I have wanted to get my own basemaps in to my web applications. I was looking at a TileServer but do not have the computer and setup to make it work. I started playing with OpenLayers because it allows you to import an image and use it as the base layer. I saw a tweet linking to a hand drawn, isometric, watercolor map of Reyjavik.

I was also playing around with importing AutoCAD in to Leaflet.js. Then I received a comment on a post that linked to FloorPlanMapper. Floorplanmapper uses AutoCAD in OpenLayers as an image like in the Reyjavik map.

So I decided to import a CAD file in OpenLayers and drop 2 points in to a room, then connect a popup to the points. This was my first attempt at OpenLayers and relied a lot on OpenLayers:PopUp Mayham.

Ideally, I would use polygons in the rooms but here is my AutoCAD and OpenLayers map:

OpenLayers is a mapping library that can be used to create applications that use CAD files as the base. Just another possibility and another reason to look cross discipline to deliver great services to your clients.

Here is my code: OpenLayerCAD

It’s Not Revit, It’s You.

15 Mar

It has to be said: Revit is not the problem, YOU ARE!

Let me explain….

I sat down this morning to listen to a licensed architect ask how to find out wall areas in Revit. After hearing the answer, the architect asked for the drawings in CAD. Because using DOS and CAD – yes, DOS was actually used, I can’t even make that up – is faster and Revit is inefficient and doesn’t do the things it needs to do. How can it have so many tools and capabilities but none of them are relevant to our work.

I hear this way too often. Revit can’t do X. Or, AutoCAD is much faster at X than Revit. This is wrong! There is very little that you can’t do in Revit, you just don’t know how (let me say that for the work I am doing there is very little it doesn’t do). CAD is faster because you have been using it for 15 years. Trust me, when you get proficient in Revit,you will find many things much faster.  I offered to put a cost formula in the template that will calculate the costs of painting the walls. “But I don’t need to paint them all.” I know, but when the model is drawn for every future project those costs will be in the model. Just select the walls you want and you are done! How about stucco? Want me to add tile and carpet on the floors? No Problem.

Was my offer accepted? NO.

Did you know you can export it to AutoCAD – sorry, we don’t have DOS so you will have to use Windows. NO.

The architect printed out the floor plan and is calculating the area with a ruler!

 

 

You are Here: Floor Plans, GIS, and QR Codes in the Building

18 Jan

I have started to see several negative posts about QR Codes. I like QR Codes. I have not, however,  seen many good uses of them – yet. I am going to show you how to use a QR Code on the room signage in your building to display a floor plan of the building in GIS with a “you are here” marker. Remember when I said architects should learn to code? This example will require a little PHP and Javascript. But do not turn away. It is VERY simple and I will provide the basic code. You just need to change a few parameters and viola! you will be up an running.

First, I am going to use Leaflet.js as my mapping engine. I am not using Google Maps because I prefer open source and when we get in to paying for Google, I am not having it. Yes, you do legally have to pay for Google when you meet certain requirements. Download and extract Leaflet to a folder on your web server.

Next, I will write the webpage to load my map. Almost all of this code is taken straight from the Leaflet.js examples section.

You will need a developer ID from Cloudmade — it’s free. The magic happens in the PHP that looks like this:

<?php echo $_GET[“lat”]; ?>, <?php echo $_GET[“long”]; ?>

This code allows me to pass data to the script in the URL of the page. The data is the coordinates of where you are standing when you scan the QR Code. So the URL for the page is http://educationalfacilityplanning.com/latlong.php?lat=XXX&long=XXX. The lat= and long = are variables called in the PHP.

Lastly, I will make the QR Codes using the URL of my page. I will grab the Latitude and Longitude of each room in the building and create a QR Code replacing the XXX shown in the URL in the previous paragraph.  My first QR Code will link to the URL: http://educationalfacilityplanning.com/latlong.php?lat=35.0967210997174&long=-106.635601453865

Here is the QR Code:

Generate a code for each room and you are done. In this example I have yet to put the floor plan on the map. There are several ways to do this, so I will leave it up to you to figure out. If you want to do it and need help, leave a comment and I will tell you how I have made it work.

UPDATE: Here is a map with Autocad in Leaflet.js. I used a WMS layer and connected to my geoserver.

To add a WMS Layer

var floorplan = new L.TileLayer.WMS(“http://localhost:8080/geoserver/cad/wms&#8221;, {
layers: ‘cad:AztecHighSchoolCAD’,
format: ‘image/png’,
transparent: true,
attribution: “Paul Crickard”
});

 

 

Any ideas on how to make this work with a 2 story building? Without having 3D GIS capabilities on my phone, my best idea so far is to create 2 base maps, one for the 1st floor and one for the 2nd. If you have a better idea, let me know. I would love to hear it.

QR Codes in CAD and Revit

1 Jun

Have you noticed the proliferation of these things in magazines?

These are QR codes. And with a smartphone and a free scanner (such as RedLaser for iPhone) a person can scan this code and be taken to your website, a map, call you, receive a message, or a number of other options — its up to you what data you embed in this code.

You can generate a code using one of several free generators such as Kaywa. Or, since we are creating drawings, we can generate them natively as a hatch in AutoCAD or as an image in Revit.

Autodesk released a plugin of the month that allows you to create a QR code inside AutoCAD. The plugin is here. Once installed just type ‘QRGEN’ and follow the GUI prompts.

These QR codes can be placed in your drawing title blocks, for example.

What I find to be of the greatest benefit is the ability to track how many people have scanned your code. By using a URL shortener such as http://bit.ly you can create a short URL for your site and bit.ly generates the QR code. By entering the URL provided with a ‘+’ sign, you will see a tally of how many people scanned your code and when. This means you can create project specific codes and monitor their effectiveness for marketing purposes.

I just provided one example of using QR codes in a drawing, and a very simple one at that. You could do a million other things, such as place one next to a detail that takes you to a 3D model of the detail. Place one on your signage at the site that takes you to a render of what the finished building will look like. Put one on your business card that updates a persons contacts using a vcard.

Happy scanning.