def create(origin: tuple): """ :type origin: (float | str, float | str) :rtype: Locus """ vs.Locus(Units.resolve_length_units(origin)) return Locus(vs.LNewObj())
def create_by_diagonal(top_left: tuple, bottom_right: tuple): """ :type top_left: (float | str, float | str) :type bottom_right: (float | str, float | str) :rtype: Rectangle """ vs.Rect(Units.resolve_length_units(top_left), Units.resolve_length_units(bottom_right)) return Rectangle(vs.LNewObj())
def create(point1: tuple, point2: tuple): """ :type point1: (float | str, float | str) :type point2: (float | str, float | str) :rtype: Line """ vs.MoveTo(Units.resolve_length_units(point1)) vs.LineTo(Units.resolve_length_units(point2)) return Line(vs.LNewObj())
def create(content_creator: callable): """ :type content_creator: () -> None :rtype: Group """ vs.BeginGroup() content_creator() vs.EndGroup() return Group(vs.LNewObj())
def create(definition: SymbolDefinition, insertion_point: tuple, rotation: float): """ :type insertion_point: (float | str, float | str) :rtype: Symbol """ vs.Symbol(definition.name, Units.resolve_length_units(insertion_point), rotation) return Symbol(vs.LNewObj())
def create(vertices: tuple, closed: bool = True): """ :type vertices: tuple[tuple[x: float|str, y: float|str]] """ vs.ClosePoly() if closed else vs.OpenPoly() vs.Poly(*[ Units.to_length_units(c) if isinstance(c, str) else c for vertex in vertices for c in vertex ]) return Polygon(vs.LNewObj())
def __SetMaterial(self): hObject = vs.LNewObj() if self.__fMaterial == LedgeMaterial.Wood: #vs.SetTextureRef(hObject, -1, 1) vs.SetFillBack(hObject, kColorIndexWood) elif self.__fMaterial == LedgeMaterial.Metal: #vs.SetTextureRef(hObject, -1, 2) vs.SetFillBack(hObject, kColorIndexMetal) else: #vs.SetTextureRef(hObject, -1, 3) vs.SetFillBack(hObject, kColorIndexPlastic)
def __DrawCurtainPoly( self, startPoint, endPoint, step ): vs.BeginPoly() vertexCnt = 1 while startPoint <= endPoint: if vertexCnt % 2 == 0: vs.Add2DVertex( self.__fOriginPoint.x + startPoint, self.__fOriginPoint.y + self.__fCurveHeight, 3, 0 ) else: vs.Add2DVertex( self.__fOriginPoint.x + startPoint, self.__fOriginPoint.y + 0, 3, 0 ) vertexCnt += 1 startPoint += step vs.EndPoly() vs.SetPolyClosed( vs.LNewObj(), False )
def DrawLedge(self): vs.BeginXtrd(0, self.__fWindowWidth * kLedgeOutWindow) hLedgePoly = self.__DrawLedgePoly() vs.EndXtrd() hLedgePoly = vs.LNewObj( ) # without that line there is a bug : multiple insertion of the object leads to whole window (oall abojects) offset hLedgePoly = self.__MoveLedge(hLedgePoly) vs.Rotate3D(0, 0, 90) vs.Rotate3D(0, 90, 0) hLedgePoly = self.__SetMaterial()
def create(origin: tuple, direction: tuple, width, height): """ :type origin: (float | str, float | str) :type direction: (float | str, float | str) :type width: float | str :type height: float | str :rtype: Rectangle """ vs.RectangleN(Units.resolve_length_units(origin), Units.resolve_length_units(direction), Units.resolve_length_units(width), Units.resolve_length_units(height)) return Rectangle(vs.LNewObj())
def create(text: str, origin: tuple, horizontal_alignment: int = None, vertical_alignment: int = None): """ :type origin: (float | str, float | str) :type horizontal_alignment: TextHorizontalAlignmentEnum :type vertical_alignment: TextVerticalAlignmentEnum :rtype: Text """ vs.TextOrigin(Units.resolve_length_units(origin)) vs.TextJust(horizontal_alignment) if horizontal_alignment else None vs.TextVerticalAlign( vertical_alignment) if vertical_alignment else None vs.CreateText(text) return Text(vs.LNewObj())
def __DrawLedgePoly(self): vs.BeginPoly() vs.Add2DVertex(-self.__fLedgeWidth / 2, 0, 0, 0) vs.Add2DVertex(-self.__fLedgeWidth / 2, -self.__fLedgeHeight, 0, 0) vs.Add2DVertex(-self.__fLedgeWidth / 2 * kLedgeShaftWidth, -self.__fLedgeHeight, 0, 0) vs.Add2DVertex(-self.__fLedgeWidth / 2 * kLedgeShaftWidth, -self.__fLedgeHeight * kLedgeShaftHeight, 0, 0) vs.Add2DVertex(self.__fLedgeWidth / 2 * kLedgeShaftWidth, -self.__fLedgeHeight * kLedgeShaftHeight, 0, 0) vs.Add2DVertex(self.__fLedgeWidth / 2 * kLedgeShaftWidth, -self.__fLedgeHeight, 0, 0) vs.Add2DVertex(self.__fLedgeWidth / 2, -self.__fLedgeHeight, 0, 0) vs.Add2DVertex(self.__fLedgeWidth / 2, 0, 0, 0) vs.EndPoly() hPoly = vs.LNewObj() vs.SetPolyClosed(hPoly, True) return hPoly
def Reset(): width = vs.PWidth height = vs.PHeight elevation = vs.PElvInWall angle = vs.POpeningAngle leafType = vs.GetRField(gObjHandle, gObjName, 'Leaf') isOpened = vs.GetRField(gObjHandle, gObjName, 'OpenTheWindow') wallType = vs.GetTypeN(gWallHandle) if (wallType == 68 or wallType == 89): thickness = vs.WallWidth(gWallHandle) else: upi = vs.GetPrefReal(152) / 25.4 thickness = 100 * upi if isOpened == "False": angle = 0 frameObj = frame.Frame(width, height, thickness, elevation, leafType, angle) frameObj.Draw() #draw curtain####################### if vs.PHasCurts: objLedge = Ledge.LedgeObj(height / 20, height / 40, width, height + elevation, vs.PLedgeMaterial, vs.PLedgeType, thickness) objLedge.DrawLedge() hObject = vs.LNewObj() if objLedge.getMaterial() == "Wood": #if self.__fMaterial == LedgeMaterial.Wood: vs.SetFillBack(hObject, Constants.kColorIndexWood) elif objLedge.getMaterial() == "Metal": #elif self.__fMaterial == LedgeMaterial.Metal: vs.SetFillBack(hObject, Constants.kColorIndexMetal) else: vs.SetFillBack(hObject, Constants.kColorIndexPlastic) curtainPieces = int( vs.Str2Num(vs.GetRField(gObjHandle, gObjName, "Pieces"))) curtainStartZ = elevation + thickness / 2 curtainStartY = thickness / 2 - objLedge.getLedgeShaftWidth( ) * 1.5 + objLedge.getLedgeWidth() curtainHeight = objLedge.getLedgeHeight( ) - objLedge.getLedgeShaftHeight() curtainWidth = width * Ledge.kLedgeOutWindow curtainCurvesWidth = 2 if curtainCurvesWidth > objLedge.getLedgeShaftWidth(): curtainCurvesWidth = objLedge.getLedgeShaftWidth() curtainOpacity = int( vs.Str2Num(vs.GetRField(gObjHandle, gObjName, 'Opacity'))) distanceBetweenCurtainPieces = 30 curtainCurveStep = 30 curtainColor = vs.Str2Num( vs.GetRField(gObjHandle, gObjName, '__CustomColor')) # distanceBetweenCurtainPieces, curtainCurveStep and curtainCurveWidth are not neccessary to add in the creation of the object curtain = Curtain(Vector(0, -curtainStartY, curtainStartZ), curtainWidth, curtainHeight, curtainColor, curtainPieces, curtainOpacity, distanceBetweenCurtainPieces, curtainCurveStep, curtainCurvesWidth) if vs.PDrawTheCurts: curtain.DrawCurtain()
def __DrawCurtainPiece(self, startPoint, endPoint, step): vs.BeginXtrd(self.__fOriginPoint.z, self.__fHeight) self.__DrawCurtainPoly(startPoint, endPoint, step) vs.EndXtrd() return vs.LNewObj()
def Draw(self): if self.leafType == kTypeNone: vs.BeginGroup() glassWidth = self.width glassHeight = self.height glassThikness = self.__glassThikness glassOrigin = (0, 0) pathDirection = (0, -1) vs.DSelectAll() vs.BeginXtrd( 0, glassThikness) vs.RectangleN( glassOrigin, pathDirection, glassWidth, glassHeight ) hGlass = vs.LNewObj() vs.EndXtrd() vs.Set3DRot(hGlass, 0, 40, 0, 0, 0, 0) vs.EndGroup() hLeaf = vs.LNewObj() #position at origin with needed orientation vs.Set3DRot(hLeaf, 0, -90, 0, 0, 0, 0) vs.Move3DObj(hLeaf, self.__frameThickness/2, 0, 0) vs.Set3DRot(hLeaf, 0, 0, 90, 0, 0, 0) if self.leafType != kTypeNone: vs.BeginGroup() #Prepare Extrude Path pathWidth = self.width + self.__frameOverlap*2 pathHeight = self.height + self.__frameOverlap*2 pathOrigin = ( -self.__frameOverlap, self.__frameOverlap ) pathDirection = (0, -1) vs.RectangleN( pathOrigin, pathDirection, pathWidth, pathHeight) hFramePath = vs.LNewObj() vs.SetPlanarRefIDToGround(hFramePath); hFramePath = vs.ConvertToNURBS(hFramePath, False) #Prepare Extrude Profile frameProfile = ( self.__frameOverlap, 0, self.__frameWidth, 0, self.__frameWidth, self.__frameThickness, 0, self.__frameThickness, 0, self.__frameInsideThinckness, self.__frameOverlap, self.__frameInsideThinckness ) vs.ClosePoly() vs.Poly(*frameProfile) hFrameProfile = vs.LNewObj() hFrameProfilePolyline = vs.MakePolyline(hFrameProfile) vs.DelObject(hFrameProfile) hFrameProfile = hFrameProfilePolyline hLeafFrame = vs.ExtrudeAlongPath(hFramePath, hFrameProfile) vs.DelObject(hFramePath) vs.DelObject(hFrameProfile) #insert glass glassWidth = self.width - 2*self.__frameMainWidth glassHeight = self.height - 2*self.__frameMainWidth glassThikness = self.__glassThikness glassOrigin = (self.__frameMainWidth, -self.__frameMainWidth) vs.DSelectAll() vs.BeginXtrd(self.__frameThickness/2, self.__frameThickness/2 + glassThikness) vs.RectangleN( glassOrigin, pathDirection, glassWidth, glassHeight ) hGlass = vs.LNewObj() vs.EndXtrd() vs.EndGroup() hLeaf = vs.LNewObj() #position at origin with needed orientation vs.Set3DRot(hLeaf, 0, -90, 0, 0, 0, 0) vs.Set3DRot(hLeaf, 0, 0, 180, 0, 0, 0) vs.Move3DObj(hLeaf, 0, -self.width, 0) vs.Set3DRot(hLeaf, 0, 0, 90, 0, 0, 0) #move to required position vs.Move3DObj(hLeaf, self.position[0], self.position[1], self.position[2], ) if self.isGlassTrue == True: vs.SetFillBack(hGlass, 11) vs.SetOpacity(hGlass, 50) else: vs.SetFillBack(hGlass, 8) vs.SetOpacity(hGlass, 100) self.hLeaf = hLeaf
def Draw(self): vs.BeginXtrd(0,self.thickness) vs.Rect(-self.width/2.0, self.height/2.0, self.width/2.0, self.height/2.0-self.thickness) r1 = vs.LNewObj() vs.Rect(-self.width/2.0, self.height/2.0-self.thickness, -self.width/2.0+self.thickness, -self.height/2.0+self.thickness) r2 = vs.LNewObj() r2 = vs.AddSurface(r1, r2) vs.Rect(self.width/2.0-self.thickness, self.height/2.0-self.thickness, self.width/2.0, -self.height/2.0+self.thickness) r3 = vs.LNewObj() r3 = vs.AddSurface(r2,r3) vs.Rect(-self.width/2.0, -self.height/2.0+self.thickness, self.width/2.0, -self.height/2.0) r4 = vs.LNewObj() r4 = vs.AddSurface(r3,r4) if (self.wingsNum == 2): vs.Rect(-self.thickness/2.0, self.height/2.0-self.thickness, self.thickness/2.0, -self.height/2.0+self.thickness) r5 = vs.LNewObj() r4 = vs.AddSurface(r4,r5) vs.EndXtrd() vs.SetRot3D(vs.LNewObj(), 90, 0, 0, 0, -self.height/2.0, 0) vs.Move3DObj(vs.LNewObj(), 0, self.height/2.0+self.thickness/2.0, 0) vs.Move3DObj(vs.LNewObj(), 0, 0, self.elevation) #instert leafs upi = vs.GetPrefReal(152) / 25.4 leafPosOffsetY = self.thickness - leaf.Leaf.kFrameThicknessNotUPI*upi posFirstLeaf = (-self.width/2.0+self.thickness, -self.thickness/2.0+leafPosOffsetY, self.elevation+self.thickness ) if self.wingsNum == 0: wingsWidth = self.width - 2.0*self.thickness wingsHeight = self.height - 2.0*self.thickness firstLeaf = leaf.Leaf(wingsWidth, wingsHeight, posFirstLeaf) firstLeaf.SetType(leaf.kTypeNone, self.isGlass) firstLeaf.Draw() elif self.wingsNum == 1: wingsWidth = self.width - 2.0*self.thickness wingsHeight = self.height - 2.0*self.thickness firstLeaf = leaf.Leaf(wingsWidth, wingsHeight, posFirstLeaf) firstLeaf.SetType(leaf.kTypeLeft, self.isGlass) firstLeaf.Draw() firstLeaf.SetOpening(self.openingAngle) elif self.wingsNum == 2: wingsWidth = (self.width - 3.0*self.thickness)/2.0 wingsHeight = self.height - 2.0*self.thickness firstLeaf = leaf.Leaf(wingsWidth, wingsHeight, posFirstLeaf) firstLeaf.SetType(leaf.kTypeLeft, self.isGlass) firstLeaf.Draw() firstLeaf.SetOpening(self.openingAngle) posSecondLeaf = (self.thickness/2.0, -self.thickness/2.0+leafPosOffsetY, self.elevation+self.thickness) secondLeaf = leaf.Leaf(wingsWidth, wingsHeight, posSecondLeaf) secondLeaf.SetType(leaf.kTypeRight, self.isGlass) secondLeaf.Draw() secondLeaf.SetOpening(self.openingAngle)
def reset_event_handler(rename_handle): # Create the Image if vs.PWithImage: image_texture = vs.GetTextureRefN(rename_handle, 0, 0, True) if image_texture: image_prop = vs.CreateImageProp(vs.PPictureName, image_texture, vs.PImageHeight, vs.PImageWidth, False, False, False, False, False) if image_prop != 0: vs.Move3DObj(image_prop, 0, (vs.PFrameDepth / 2) - vs.PImagePosition, 0) existing_texture = vs.GetObject("{} Picture Texture".format(vs.GetName(rename_handle))) if existing_texture: set_name(existing_texture, "{} Previous Picture Texture".format(vs.GetName(rename_handle))) vs.SetName( vs.GetObject(vs.Index2Name(image_texture)), "{} Picture Texture".format(vs.GetName(rename_handle))) else: vs.SetRField(rename_handle, "Picture", "WithImage", "False") vs.DelObject(vs.GetObject(vs.Index2Name(image_texture))) vs.AlertCritical("Error creating Picture object", "Close/Open VectorWorks and retry the operation") # Create the Frame if vs.PWithFrame: vs.BeginPoly3D() vs.Add3DPt((-vs.PFrameWidth / 2, -(vs.PFrameDepth / 2), -(vs.PFrameHeight - vs.PImageHeight) / 2)) vs.Add3DPt((vs.PFrameWidth / 2, -(vs.PFrameDepth / 2), -(vs.PFrameHeight - vs.PImageHeight) / 2)) vs.Add3DPt((vs.PFrameWidth / 2, -(vs.PFrameDepth / 2), vs.PFrameHeight - ((vs.PFrameHeight - vs.PImageHeight) / 2))) vs.Add3DPt((-vs.PFrameWidth / 2, -(vs.PFrameDepth / 2), vs.PFrameHeight - ((vs.PFrameHeight - vs.PImageHeight) / 2))) vs.Add3DPt((-vs.PFrameWidth / 2, -(vs.PFrameDepth / 2), -(vs.PFrameHeight - vs.PImageHeight) / 2)) vs.EndPoly3D() extrude_path = vs.LNewObj() extrude_path = vs.ConvertToNURBS(extrude_path, False) vs.Rect((-1 * vs.PFrameThickness, -1 * vs.PFrameDepth), (0, 0)) extrude_profile = vs.LNewObj() frame = vs.ExtrudeAlongPath(extrude_path, extrude_profile) vs.DelObject(extrude_path) vs.DelObject(extrude_profile) vs.SetClass(frame, vs.PFrameClass) vs.SetFPatByClass(frame) vs.SetFillColorByClass(frame) vs.SetLSByClass(frame) vs.SetLWByClass(frame) vs.SetMarkerByClass(frame) vs.SetOpacityByClass(frame) vs.SetPenColorByClass(frame) vs.SetTextStyleByClass(frame) vs.SetTextureRefN(frame, -1, 0, 0) vs.SetTexMapRealN(frame, 3, 0, 3, vs.PFrameTextureScale) vs.SetTexMapRealN(frame, 3, 0, 4, vs.Deg2Rad(vs.PFrameTextureRotation)) # Create the Matboard if vs.PWithMatboard: # vs.BeginPoly3D() # vs.Add3DPt((-vs.PFrameWidth / 2, (vs.PFrameDepth / 2) - vs.PMatboardPosition, -(vs.PFrameHeight - vs.PImageHeight) / 2)) # vs.Add3DPt((vs.PFrameWidth / 2, (vs.PFrameDepth / 2) - vs.PMatboardPosition, -(vs.PFrameHeight - vs.PImageHeight) / 2)) # vs.Add3DPt((vs.PFrameWidth / 2, (vs.PFrameDepth / 2) - vs.PMatboardPosition, vs.PFrameHeight - ((vs.PFrameHeight - vs.PImageHeight) / 2))) # vs.Add3DPt((-vs.PFrameWidth / 2, (vs.PFrameDepth / 2) - vs.PMatboardPosition, vs.PFrameHeight - ((vs.PFrameHeight - vs.PImageHeight) / 2))) # vs.Add3DPt((-vs.PFrameWidth / 2, (vs.PFrameDepth / 2) - vs.PMatboardPosition, -(vs.PFrameHeight - vs.PImageHeight) / 2)) # vs.EndPoly3D() # matboard = vs.LNewObj() vs.BeginMXtrd(0, 0.01) vs.Rect((-vs.PFrameWidth / 2, vs.PFrameHeight / 2), (vs.PFrameWidth / 2, -vs.PFrameHeight / 2)) vs.Rect((-vs.PFrameWidth / 2, vs.PFrameHeight / 2), (vs.PFrameWidth / 2, -vs.PFrameHeight / 2)) vs.EndMXtrd() matboard = vs.LNewObj() vs.BeginMXtrd(0, 0.01) vs.Rect((-vs.PWindowWidth / 2, vs.PWindowHeight / 2), (vs.PWindowWidth / 2, -vs.PWindowHeight / 2)) vs.Rect((-vs.PWindowWidth / 2, vs.PWindowHeight / 2), (vs.PWindowWidth / 2, -vs.PWindowHeight / 2)) vs.EndMXtrd() window = vs.LNewObj() result, new_object = vs.SubtractSolid(matboard, window) vs.Set3DRot(new_object, 90, 0, 0, 0, 0, 0) vs.Move3DObj(new_object, 0, (vs.PFrameDepth / 2) - vs.PMatboardPosition + 0.01, vs.PImageHeight / 2) vs.SetClass(new_object, vs.PMatboardClass) vs.SetFPatByClass(new_object) vs.SetFillColorByClass(new_object) vs.SetLSByClass(new_object) vs.SetLWByClass(new_object) vs.SetMarkerByClass(new_object) vs.SetOpacityByClass(new_object) vs.SetPenColorByClass(new_object) vs.SetTextStyleByClass(new_object) vs.SetTextureRefN(new_object, -1, 0, 0) vs.SetTexMapRealN(new_object, 3, 0, 3, vs.PMatboardTextureScale) vs.SetTexMapRealN(new_object, 3, 0, 4, vs.Deg2Rad(vs.PMatboardTextureRotat)) # Create the Glass if vs.PWithGlass: vs.BeginPoly3D() vs.Add3DPt((-vs.PFrameWidth / 2, (vs.PFrameDepth / 2) - vs.PGlassPosition, -(vs.PFrameHeight - vs.PImageHeight) / 2)) vs.Add3DPt((vs.PFrameWidth / 2, (vs.PFrameDepth / 2) - vs.PGlassPosition, -(vs.PFrameHeight - vs.PImageHeight) / 2)) vs.Add3DPt((vs.PFrameWidth / 2, (vs.PFrameDepth / 2) - vs.PGlassPosition, vs.PFrameHeight - ((vs.PFrameHeight - vs.PImageHeight) / 2))) vs.Add3DPt((-vs.PFrameWidth / 2, (vs.PFrameDepth / 2) - vs.PGlassPosition, vs.PFrameHeight - ((vs.PFrameHeight - vs.PImageHeight) / 2))) vs.Add3DPt((-vs.PFrameWidth / 2, (vs.PFrameDepth / 2) - vs.PGlassPosition, -(vs.PFrameHeight - vs.PImageHeight) / 2)) vs.EndPoly3D() glass = vs.LNewObj() vs.SetClass(glass, vs.PGlassClass) vs.SetFPatByClass(glass) vs.SetFillColorByClass(glass) vs.SetLSByClass(glass) vs.SetLWByClass(glass) vs.SetMarkerByClass(glass) vs.SetOpacityByClass(glass) vs.SetPenColorByClass(glass) vs.SetTextStyleByClass(glass) vs.SetTextureRefN(glass, -1, 0, 0)
def ImportSym(GoboSize, GoboScale): symCreatedCnt = 0 # define a location to import the images importPt = (0, 0) #Set Origin xOrigin = 0 yOrigin = 0 #Set Final Bounding Box Size BBL, BBR = ConvertSize(GoboSize) major, minor, maintenance, platform = vs.GetVersion() isMac = False if platform == 1: isMac = True err, dirPath = vs.GetFolder('Select a Folder') if err == 0: # no-error hsfDirPath = dirPath if isMac: ok, hsfDirPath = vs.ConvertPosix2HSFPath(dirPath) fileIndex = 1 while True: # loop the files fileName = vs.GetFilesInFolder(hsfDirPath, fileIndex) fileIndex += 1 if fileName == '': # no more files return symCreatedCnt name, ext = os.path.splitext(fileName) if ext.lower() == '.png' or ext.lower() == '.jpg' or ext.lower( ) == '.jpeg' or ext.lower() == '.gif': imagePath = os.path.join(dirPath, fileName) vs.BeginSym(name) hImage = vs.ImportImageFile(imagePath, importPt) #Set image size hImage = vs.PickObject(0, 0) vs.SetBBox(hImage, BBL, BBR) #Draw Oval and set HANDLE var OvalBBL = (xOrigin, yOrigin) OvalBBR = ((abs(BBL[0]) + abs(BBR[0])), -(abs(BBL[1]) + abs(BBR[1]))) vs.Oval(OvalBBL, OvalBBR) hCrop = vs.LNewObj() #Scale image vs.HScale2D(hImage, 0, 0, GoboScale, GoboScale, 0) #Move the crop oval to the bottom right corner of the gobo image xCropMove = ((BBR[0] * GoboScale) - BBR[0]) yCropMove = ((BBR[1] * GoboScale) - BBR[1]) vs.HMove(hCrop, xCropMove, yCropMove) #Crop dat vs.SetImageCropObject(hImage, hCrop) #Finish vs.EndSym() symCreatedCnt += 1