Silas Posted November 16, 2018 Share Posted November 16, 2018 (edited) 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[0] ay = point1[1] bx = point2[0] by = point2[1] cx = point3[0] cy = point3[1] dx = point4[0] dy = point4[1] elif countvert <= 5: ax = point1[0] ay = point1[1] bx = point2[0] by = point2[1] cx = point3[0] cy = point3[1] dx = point4[0] dy = point4[1] ex = point5[0] ey = point5[1] else: ax = point1[0] ay = point1[1] bx = point2[0] by = point2[1] cx = point3[0] cy = point3[1] dx = point4[0] dy = point4[1] ex = point5[0] ey = point5[1] fx = point6[0] fy = point6[1] 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: angle = vs.Rad2Deg(vs.ArcTan(gk/ak)) m = gk / ak elif bc > cd and bc > de and bc > ef: gk = cy - by ak = cx - bx if ak != 0: angle = vs.Rad2Deg(vs.ArcTan(gk/ak)) m = gk / ak elif cd > de and cd > ef: gk = dy - cy ak = dx - cx if ak != 0: angle = vs.Rad2Deg(vs.ArcTan(gk/ak)) m = gk / ak elif de > ef: gk = ey - dy ak = ex - dx if ak != 0: angle = vs.Rad2Deg(vs.ArcTan(gk/ak)) m = gk / ak else: gk = fy - ey ak = fx - ex if ak != 0: angle = vs.Rad2Deg(vs.ArcTan(gk/ak)) 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[0] == True: if input_hatch == hatch_h[1]: 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 November 21, 2018 by Silas 1 Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.