## GridLayout.py Version 1.09

## Copyright (c) 2006 Bruce Vaughan, BV Detailing & Design, Inc.

## All rights reserved.

## NOT FOR SALE. The software is provided "as is" without any warranty.

############################################################################

"""

Read a text file containing grid and arc information and layout the grid lines of a building as

construction lines and circles. Version 1.08 and greater can read line, arc and circle data

from DXF files.

SDS/2 parametrics cannot add EVUs at the present time.

This script was orignally intended to work in plan. ExplicitL' lines and 'ExplicitR' circles work

in any model orientation, but will be created only in the current model orientation. This is a

limitation of SDS/2.

 

This script is compatible with GridSave.py.

For Construction Lines - 'Direction' = the angle of the construction line

For Construction Circles - 'Circle' work points are translated in 'Direction' from 'Origin'

'Origin' and 'Direction' must precede 'Circle' and offset dimensions

Text File Format:

# Comment Line

ExplicitL: 20-0, 20-0, 20-0 : 40-0, 40-0, 40-0

ExplicitA: 20-0, 20-0, 20-0 : 45

ExplicitR: 20-0, 20-0, 20-0 : 15-0

Origin:0.0,0.0

Direction: 45.0

Circle: 125-6 3/4, 66-9 7/16 :44-5

Circle: 125-6 3/4, 66-9 7/16 :44-0

Circle: 125-6 3/4, 66-9 7/16 :43-7

Origin:0.0,0.0

Direction:-90.0

41-5

42-8

......

Origin:0.0,0.0

Direction:0.0

1-11 1/2

1-0 1/2

.......

 

Origin has x and y components only

Direction should be between 180 and -180 degrees

If 'Direction' = 90 degrees, construction lines are progressively added in the negative 'x' direction.

If 'Direction' = 0 degrees, construction lines are progressively added in the positive 'y' direction.

 

Version History:

Version 1.00 (11/8/06) - Initial release

Version 1.01 (11/8/06) - Optimize

Version 1.02 (11/13/06) - Add construction circles

Version 1.03 (11/14/06) - Add 'ExplicitL' construction lines (2 points)

Add 'ExplicitR' construction circles

Add option to print documentation to report viewer

Version 1.04 (11/15/06) - Add 'ExplicitA' construction lines (1 point and the angle)

Version 1.05 (11/27/06) - Eliminate imports string and types

Version 1.06 (1/16/07) - Add comment lines. Comment lines begin with '#'.

Version 1.07 (1/17/07) - Change 'elif str in item' to 'elif item.lower().startswith(str)'

Version 1.08 (5/10/07) - Import GridDXF

Add capability of reading lines, circles and arcs from a DXF file.

Version 1.09 (5/10/07) - Add capability of selecting base point for DXF file import.

"""

def run_script():

try:

from param import ResponseNotOK, Units, Dialog, Warning, dim

from macrolib.ExceptWarn import formatExceptionInfo

from macrolib.PolarPt import polar_pt_plan

from macrolib.PrintPtList import formatPtList

from macrolib.GridDXF import parseDXFpts, formatDXFpts

from point import Point

from point import PointLocate

from job import JobName

from cons_line import ConsLine

from cons_circle import ConsCircle

import os

import re

Units("feet")

#####################################

def gridAdd(pt, dir, cons_color="Cyan"):

# construction line begin

cl2 = ConsLine()

cl2.pt1 = pt

cl2.angle = dir

cl2.pen = cons_color

cl2.add()

# construction line end

#####################################

def gridAddExplicit(pt1, pt2, cons_color="Cyan"):

# construction line begin

cl2 = ConsLine()

cl2.pt1 = pt1

cl2.pt2 = pt2

cl2.pen = cons_color

cl2.add()

# construction line end

####################################

def arcAdd(pt, rad, cons_color="Red"):

cc1 = ConsCircle()

cc1.pt1 = pt

cc1.radius = rad

cc1.pen = cons_color

cc1.add()

while 1:

## Dialog Box ######################

dlg1 = Dialog("Building Grid Lines in Plan")

dlg1.menu("print_doc", ("Yes", "No"), "No", "Print script documentation ")

dlg1.group_title("Import Grid Line File")

dlg1.file('import_file', os.path.join(os.getcwd(), "jobs", JobName(), "macro", "Test1.txt"), "Enter file name or browse ")

dlg1.menu('cons_color', ("Blue", "Green", "Yellow", "Magenta", "Red", "White", "Cyan"), "Cyan", "Construction line color")

dlg1.menu('conc_color', ("Blue", "Green", "Yellow", "Magenta", "Red", "White", "Cyan"), "Red", "Construction circle color")

try:

dlg1.done()

except ResponseNotOK:

raise

if dlg1.print_doc == "Yes":

print __doc__

break

 

if os.path.splitext(dlg1.import_file)[-1].lower() == '.dxf':

# Create a list object if user selects a dxf file

pt = PointLocate("Select base point for DXF file import or return")

if pt:

f = formatDXFpts(base=(pt.x, pt.y, pt.z), *(parseDXFpts(dlg1.import_file))).split('\n')

else:

f = formatDXFpts(*(parseDXFpts(dlg1.import_file))).split('\n')

else:

# Create a file object otherwise

# Import grid line file

try:

f = open(dlg1.import_file, "r")

except IOError, e:

# unable to open file

Warning("Unable to open file: %s" % (e))

 

# Iteration on list or file object

# 'for' calls file or list next() method

for item in f:

if item.startswith('#'):

pass

elif item.lower().startswith('explicitl'):

pt = re.split('[:;,]', item)

ptWP1 = Point(dim(pt[1].strip()), dim(pt[2].strip()), dim(pt[3].strip()))

ptWP2 = Point(dim(pt[4].strip()), dim(pt[5].strip()), dim(pt[6].strip()))

gridAddExplicit(ptWP1, ptWP2, dlg1.cons_color)

elif item.lower().startswith('explicita'):

pt = re.split('[:;,]', item)

ptWP1 = Point(dim(pt[1].strip()), dim(pt[2].strip()), dim(pt[3].strip()))

ang1 = dim(pt[4].strip())

gridAdd(ptWP1, ang1, dlg1.cons_color)

elif item.lower().startswith('explicitr'):

pt = re.split('[:;,]', item)

ptWP1 = Point(dim(pt[1].strip()), dim(pt[2].strip()), dim(pt[3].strip()))

arcAdd(ptWP1, dim(pt[4].strip()), dlg1.conc_color)

elif item.lower().startswith('origin'):

ptx, pty = item.split(':')[1].split(",")

gridWP = Point(dim(ptx.strip()), dim(pty.strip()), 0.0)

elif item.lower().startswith('direction'):

gridOffset = 0.0

gridDir = dim(item.split(':')[1].strip())

gridAdd(gridWP, gridDir, dlg1.cons_color)

elif item.lower().startswith('circle'):

_str, ptWPx, ptWPy, arc_rad = re.split('[:,]', item)

pt1 = Point(dim(ptWPx.strip()), dim(ptWPy.strip()), 0.0)

ptWP = polar_pt_plan(polar_pt_plan(gridWP, pt1.x, gridDir), pt1.y, gridDir + 90.0)

arcAdd(ptWP, dim(arc_rad.strip()), dlg1.conc_color)

else:

if dim(item.strip()):

gridOffset = gridOffset + dim(item.strip())

gridAdd(polar_pt_plan(gridWP, gridOffset, gridDir + 90.0), gridDir, dlg1.cons_color)

if isinstance(f, file):

f.close()

break

except:

Warning(formatExceptionInfo())

## END run_script() #########################

if __name__ == '__main__':

try:

run_script()

finally:

del run_script

# SAMPLE DATA FILES

# Corporate Center IV Tampa, FL

# Column Grids

Origin: 0-0, 0-0

Direction: 0.0

3-0

2-0

4-0

2-6

15-0

30-0

30-0

30-0

15-0

2-6

4-0

2-0

3-0

 

Origin: 0-0, 0-0

Direction:-90.0

 

2-6

2-6

15-0

30-0

30-0

20-6

9-6

29-0

9-6

20-6

30-0

30-0

15-0

2-6

2-6

 

# Save1.txt Inwood Station

ExplicitR: 810.0000, 86.3750, 5804.25 : 174.7500

ExplicitR: 810.0000, 381.6250, 5804.25 : 174.7500

ExplicitR: 810.0000, 86.3750, 5804.25 : 182.7500

ExplicitR: 810.0000, 381.6250, 5804.25 : 182.7500

ExplicitR: 810.0000, 234.0000, 5886.75 : 89.2500

ExplicitR: 810.0000, 234.0000, 5886.75 : 97.2500

ExplicitA: 1350.0000, 234.0000, 5828.25 : -0.4911

ExplicitA: 1350.0000, 234.0000, 5828.25 : 0.4911

 

# Lenox Grids and Beams

Origin: 0-0, 0-0

Direction: 0.0

2-2

57-9

 

Origin: 0-0, 0-0

Direction:-90.0

 

19-6

19-6

19-6

 

Origin: 0-0, 0-0

Direction: 0.0

2-2

17-10 1/4

8-8

11 3/4

22-0

8-3

 

 

Origin: 0-0, 0-0

Direction:-90.0

4-10 1/2

4-10 1/2

4-10 1/2

4-10 1/2

4-6

 

Origin: 0-0, 0-0

Direction:-90.0

29-10

9-2

4-1

4-1 1/4

4-1

7-2 3/4

 

Origin: 0-0, 0-0

Direction:-90.0

29-10

19-0