Archive | AutoCAD RSS feed for this section

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.

Advertisements

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.

Shapefiles in Revit: Method II

25 Oct

Need to get shapefiles from your GIS in to Revit? I will tell you how using open source software. But first, Revit does not like coverages of over 20 miles so you may need to crop your shapefile.

Download Qgis – a free and open source GIS.

Open your shapefile in Qgis.

It will appear in the table of contents on the left. Right click on it and select ‘Save as..’ Choose AutoCAD DXF.

You now have a DXF of your shapefile.

Want to bring AutoCAD – or Revit – to GIS? Do everything in Reverse. But first activate your plugins.

Go to ‘Plugins’ and ‘Manage Plugins’. Check DXF2SHP.

Now click DXF2SHP and select your DXF. Choose a name and location to save your shapefile. Select the type. Probably polyline.

Here is a DXF loaded

Now your CAD drawing can be used in a GIS.

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

AutoCAD WS: Geolocation

31 Mar

In the new AutocAD WS update for iPhone there is now a set location, my location, and mark toolbar. I was hoping that I could add my location and then press “my location” and as I walked around the building the blue dot would move. This seems pretty easy using the geolocation features built in to the phone – I have a map that does it and it’s not even a full blown app. What the app did do was allow me to select my location and then I could view the drawing in Google Earth. My drawing is not properly scaled so it’s huge but I will post the pictures below. As someone who likes to place CAD drawings in GIS, it annoys me when I open a drawing and see it being drawn in the ocean. I hate 0,0. I always end up opening drawings and moving them to the correct position. So being able to just stand at the corner of a building and select my current location saves me some time.

Autodesk is really improving AutoCAD WS and I am enjoying it – they added 3D views as well! Let me walk the building or site and update my location in the drawing and I will be an even happier user.

Here are the pictures showing setting location, my location, and mark. Lastly, on Google Earth in the desktop browser app.

      

Download A Building

16 Mar
DeadDrops USB in A Wall

Dead Drop

I have seen this image on many webpages and found it interesting. Googling it, I found the website from which it came – Dead Drops.

According to the website:

‘Dead Drops’ is an anonymous, offline, peer to peer file-sharing network in public space. USB flash drives are embedded into walls, buildings and curbs accessible to anybody in public space. Everyone is invited to drop or find files on a dead drop. Plug your laptop to a wall, house or pole to share your favorite files and data. Each dead drop is installed empty except a readme.txt file explaining the project. ‘Dead Drops’ is open to participation.

This project made me think, what if you could plug in to a building and download that building? What if, when you plug in to the USB stick, you are presented with a local webpage (HTML file) containing access to the floor plan, maintenance logs, sensor data, etc..

Using an AutoRun script like we did for CDs – back when we used CDs – we can present the files with a web based front end without actually connecting to the web.

So why do this? Why not just put the files on the web or let someone connect to our network and look at the files?

  1. I may not want my sensitive files – floor plans – on the web.
  2. If I put them on my intranet, I have to let this person on and this opens up the possibility that they can get to other things.
  3. Of course I have a backup, but say this person deletes or corrupts the files on my intranet and I didn’t? If they delete the USB stick, I still have my originals.
  4. This lets me provide a place for a consultant, or emergency responders, to plug in and have everything they need in one place.

None of these reasons are great. The real reason to do this is because it is cool. The physically connecting a computer to a building and then seeing all the information about the building is an experience that is not obtained by going online to a website or opening a file.

But I have been asked by school districts to give them floor plans of their facilities so they can place them in a box that is accessible to first responders so that they can get information when arriving on scene. So why paper? How about a USB stick in a box with a cable they can plug in to?

Practical? Who knows.

Cool? Yup!