## Recommended Posts

Hey,

My Problem: (Static Solved Code attached)

At the moment we rotate the hatch after each DWG Import.

Normally not a big deal but because in this project we get so much input it's nearly impossible - or a full time job.

So the goal is to get this rotation with a script.

before i continue to create for each object a individual hatch, is there a function to just rotate the hatch in a object?

something like vs.RotateHatch(h, rotation) ?

My attempt at the moment: (beside recording the position and coordinates from each object - and get the rotation)

SOLVED Updated Version for Static Hatch:

------------------------------------------------------
cp = ("(T=POLY)")
cl = ("(T=POLYLINE)")

input_hatch = vs.StrDialog('Schraffur Name eingeben','')
input_hatch_angle = int(vs.StrDialog('Winkel der Schraffur als Zahl angeben: Bsp: 45, 30 etc',''))

def GetRotation(h):

global m
m = float()

global rotation
rotation = float()

global angle
angle = float()

for vertexNum in range(0, vs.GetVertNum(h)):
point, v_type_nil, angle_nil = vs.GetPolylineVertex(h, vertexNum)

point1, v_type_nil, angle_nil = vs.GetPolylineVertex(h,1)
point2, v_type_nil, angle_nil = vs.GetPolylineVertex(h,2)
point3, v_type_nil, angle_nil = vs.GetPolylineVertex(h,3)
point4, v_type_nil, angle_nil = vs.GetPolylineVertex(h,4)
point5, v_type_nil, angle_nil = vs.GetPolylineVertex(h,5)
point6, v_type_nil, angle_nil = vs.GetPolylineVertex(h,6)

#Richtungsvektoren:
#AB = B - A = [1, -1] - [-3, 2] = [4, -3]

ax = float(0.0)
ay = float(0.0)

bx = float(0.0)
by = float(0.0)

cx = float(0.0)
cy = float(0.0)

dx = float(0.0)
dy = float(0.0)

ex = float(0.0)
ey = float(0.0)

fx = float(0.0)
fy = float(0.0)

ab = float(0.0)
bc = float(0.0)
cd = float(0.0)
de = float(0.0)
ef = float(0.0)

de_x = float(0.0)
de_y = float(0.0)

ef_x = float(0.0)
ef_y = float(0.0)

countvert = int(vs.GetVertNum(h))

if countvert <= 4:
ax = point1
ay = point1

bx = point2
by = point2

cx = point3
cy = point3

dx = point4
dy = point4

elif countvert <= 5:

ax = point1
ay = point1

bx = point2
by = point2

cx = point3
cy = point3

dx = point4
dy = point4

ex = point5
ey = point5

else:

ax = point1
ay = point1

bx = point2
by = point2

cx = point3
cy = point3

dx = point4
dy = point4

ex = point5
ey = point5

fx = point6
fy = point6

if countvert <= 4:
ab_x = bx - ax
ab_y = by - ay

bc_x = cx - bx
bc_y = cy - by

cd_x = dx - cx
cd_y = dy - cy

elif countvert == 5:
ab_x = bx - ax
ab_y = by - ay

bc_x = cx - bx
bc_y = cy - by

cd_x = dx - cx
cd_y = dy - cy

else:
ab_x = bx - ax
ab_y = by - ay

bc_x = cx - bx
bc_y = cy - by

cd_x = dx - cx
cd_y = dy - cy

de_x = ex - dx
de_y = ey - dy

ef_x = fx - ex
ef_y = fy - ey

#    vs.CreateText(str(de_x))
#    vs.CreateText(str(de_y))

ab = vs.Sqrt(ab_x * ab_x + ab_y * ab_y)
bc = vs.Sqrt(bc_x * bc_x + bc_y * bc_y)
cd = vs.Sqrt(cd_x * cd_x + cd_y * cd_y)
de = vs.Sqrt(de_x * de_x + de_y * de_y)
ef = vs.Sqrt(ef_x * ef_x + ef_y * ef_y)

#    listdist = [ab,bc,cd,de,ef]
#    vs.CreateText(str(listdist))

#    vs.AlrtDialog(str(dx))
#    vs.AlrtDialog(str(dy))

if ab > bc and ab > cd and ab > de and ab > ef:
gk = by - ay
ak = bx - ax
#vs.AlrtDialog(str(gk))
#vs.AlrtDialog(str(ak))
if ak != 0:
m = gk / ak

elif bc > cd and bc > de and bc > ef:
gk = cy - by
ak = cx - bx

if ak != 0:
m = gk / ak

elif cd > de and cd > ef:
gk = dy - cy
ak = dx - cx

if ak != 0:
m = gk / ak

elif de > ef:
gk = ey - dy
ak = ex - dx

if ak != 0:
m = gk / ak

else:
gk = fy - ey
ak = fx - ex

if ak != 0:
m = gk / ak

#vs.AlrtDialog(str(angle))

if gk == 0:
angle = 0
if ak == 0:
angle = 90
if angle < 0:
angle = - angle

#IF Function
#0
if input_hatch_angle == 0:
if angle == 0:
rotation = 90
if angle == 90:
rotation = 0
else:
if m > 0:
rotation = - 90 + angle
if m < 0:
rotation = 90 - angle

#90
if input_hatch_angle == 90:
if angle == 0:
rotation = 0
if angle == 90:
rotation = 90
else:
if m > 0:
rotation = angle
if m < 0:
rotation = - angle

#45
if input_hatch_angle == 45:
if angle == 90:
rotation = 0
if angle == 0:
rotation = 0
else:
if m > 0:
rotation = - angle
if m < 0:
rotation = 90 - angle

#Hatch Control / Rotation

hatch_h = vs.GetVectorFill(h)

#vs.AlrtDialog(str(hatch_h))

# Attribute Control and Record

if hatch_h == True:
if input_hatch == hatch_h:
vs.CreateStaticHatchFromObject(h,input_hatch,0,0,rotation)

#    vs.AlrtDialog(hatch_h)

vs.ForEachObject(GetRotation,cp)
vs.ForEachObject(GetRotation,cl)
#h = vs.LNewObj()
#vs.SelectObj(h)
#vs.SelectObj(cl)
#vs.SelectObj(cp)
-------------------------------------------

thank you

Silas

Edited by Silas

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×

• KBASE