def set_name(object_handle, name): final_name = name index = 1 if vs.GetObject(final_name): while vs.GetObject(final_name + " - {}".format(index)): index += 1 vs.SetName(object_handle, final_name + " - {}".format(index)) else: vs.SetName(object_handle, final_name)
def __CreateTexture( self ): counter = 1 textureName = self.__fDefaultName while vs.GetObject( textureName ) != vs.Handle(): textureName = self.__fDefaultName + '-' + vs.Num2Str( 0, counter ) counter += 1 curtainTexture = vs.CreateTexture() vs.CreateShaderRecord( curtainTexture, kColorFamilyIndex, kPlainColorIndex ) recHand = vs.CreateShaderRecord( curtainTexture, kTransparencyFamilyIndex, kPlainTransparencyIndex ) vs.SetName( curtainTexture, textureName ) self.__fTextureHand = curtainTexture self.__SetColor() self.__SetOpacity( recHand ) self.__fRefNum = vs.Name2Index( textureName ) return textureName
def select_image_texture(self) -> None: """ Selects the texture image for the picture object s""" if self.parameters.imageTexture == "": texture = vs.CreateTexture() else: texture = vs.GetObject(self.parameters.imageTexture) vs.EditTexture(texture) shader = vs.GetShaderRecord(texture, 1) bitmap = vs.GetTextureBitmap(shader) if not bitmap: vs.DelObject(shader) vs.DelObject(texture) self.parameters.imageTexture = "" else: self.parameters.imageTexture = "{} Prop Texture".format( self.parameters.pictureName) vs.SetName(texture, self.parameters.imageTexture) shader = vs.GetShaderRecord(texture, 1) bitmap = vs.GetTextureBitmap(shader) vs.SetTexBitRepHoriz(bitmap, False) vs.SetTexBitRepVert(bitmap, False)
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 dialog_handler(self, item: int, data: int) -> int: """ Handles dialog control events """ if item == KDialogInitEvent: vs.SetItemText(self.dialog, self.kWidgetID_pictureName, self.parameters.pictureName) # Image Widgets # =============================================================================================== vs.EnableItem( self.dialog, self.kWidgetID_imageWidthLabel, vs.GetBooleanItem(self.dialog, self.kWidgetID_withImage)) vs.EnableItem( self.dialog, self.kWidgetID_imageWidth, vs.GetBooleanItem(self.dialog, self.kWidgetID_withImage)) vs.EnableItem( self.dialog, self.kWidgetID_imageHeightLabel, vs.GetBooleanItem(self.dialog, self.kWidgetID_withImage)) vs.EnableItem( self.dialog, self.kWidgetID_imageHeight, vs.GetBooleanItem(self.dialog, self.kWidgetID_withImage)) vs.EnableItem( self.dialog, self.kWidgetID_imagePositionLabel, vs.GetBooleanItem(self.dialog, self.kWidgetID_withImage)) vs.EnableItem( self.dialog, self.kWidgetID_imagePosition, vs.GetBooleanItem(self.dialog, self.kWidgetID_withImage)) vs.EnableItem( self.dialog, self.kWidgetID_imageEditButton, vs.GetBooleanItem(self.dialog, self.kWidgetID_withImage)) # Frame Widgets # =============================================================================================== vs.EnableItem( self.dialog, self.kWidgetID_frameWidthLabel, vs.GetBooleanItem(self.dialog, self.kWidgetID_withImage)) vs.EnableItem( self.dialog, self.kWidgetID_frameWidth, vs.GetBooleanItem(self.dialog, self.kWidgetID_withImage)) vs.EnableItem( self.dialog, self.kWidgetID_frameHeightLabel, vs.GetBooleanItem(self.dialog, self.kWidgetID_withImage)) vs.EnableItem( self.dialog, self.kWidgetID_frameHeight, vs.GetBooleanItem(self.dialog, self.kWidgetID_withImage)) vs.EnableItem( self.dialog, self.kWidgetID_frameThicknessLabel, vs.GetBooleanItem(self.dialog, self.kWidgetID_withImage)) vs.EnableItem( self.dialog, self.kWidgetID_frameThickness, vs.GetBooleanItem(self.dialog, self.kWidgetID_withImage)) vs.EnableItem( self.dialog, self.kWidgetID_frameDepthLabel, vs.GetBooleanItem(self.dialog, self.kWidgetID_withImage)) vs.EnableItem( self.dialog, self.kWidgetID_frameDepth, vs.GetBooleanItem(self.dialog, self.kWidgetID_withImage)) vs.EnableItem( self.dialog, self.kWidgetID_frameClassLabel, vs.GetBooleanItem(self.dialog, self.kWidgetID_withImage)) vs.EnableItem( self.dialog, self.kWidgetID_frameClass, vs.GetBooleanItem(self.dialog, self.kWidgetID_withImage)) vs.EnableItem( self.dialog, self.kWidgetID_frameTextureScaleLabel, vs.GetBooleanItem(self.dialog, self.kWidgetID_withImage)) vs.EnableItem( self.dialog, self.kWidgetID_frameTextureScale, vs.GetBooleanItem(self.dialog, self.kWidgetID_withImage)) vs.EnableItem( self.dialog, self.kWidgetID_frameTextureRotationLabel, vs.GetBooleanItem(self.dialog, self.kWidgetID_withImage)) vs.EnableItem( self.dialog, self.kWidgetID_frameTextureRotation, vs.GetBooleanItem(self.dialog, self.kWidgetID_withImage)) # Matboard Widgets # =============================================================================================== vs.EnableItem( self.dialog, self.kWidgetID_matboardPositionLabel, vs.GetBooleanItem(self.dialog, self.kWidgetID_withMatboard)) vs.EnableItem( self.dialog, self.kWidgetID_matboardPosition, vs.GetBooleanItem(self.dialog, self.kWidgetID_withMatboard)) vs.EnableItem( self.dialog, self.kWidgetID_matboardClassLabel, vs.GetBooleanItem(self.dialog, self.kWidgetID_withMatboard)) vs.EnableItem( self.dialog, self.kWidgetID_matboardClass, vs.GetBooleanItem(self.dialog, self.kWidgetID_withMatboard)) vs.EnableItem( self.dialog, self.kWidgetID_matboardTextureScaleLabel, vs.GetBooleanItem(self.dialog, self.kWidgetID_withMatboard)) vs.EnableItem( self.dialog, self.kWidgetID_matboardTextureScale, vs.GetBooleanItem(self.dialog, self.kWidgetID_withMatboard)) vs.EnableItem( self.dialog, self.kWidgetID_matboardTextureRotatLabel, vs.GetBooleanItem(self.dialog, self.kWidgetID_withMatboard)) vs.EnableItem( self.dialog, self.kWidgetID_matboardTextureRotat, vs.GetBooleanItem(self.dialog, self.kWidgetID_withMatboard)) # Glass Widgets # =============================================================================================== vs.EnableItem( self.dialog, self.kWidgetID_glassPositionLabel, vs.GetBooleanItem(self.dialog, self.kWidgetID_withGlass)) vs.EnableItem( self.dialog, self.kWidgetID_glassPosition, vs.GetBooleanItem(self.dialog, self.kWidgetID_withGlass)) vs.EnableItem( self.dialog, self.kWidgetID_glassClassLabel, vs.GetBooleanItem(self.dialog, self.kWidgetID_withGlass)) vs.EnableItem( self.dialog, self.kWidgetID_glassClass, vs.GetBooleanItem(self.dialog, self.kWidgetID_withGlass)) elif item == self.kWidgetID_pictureName: self.parameters.pictureName = vs.GetItemText( self.dialog, self.kWidgetID_pictureName) elif item == self.kWidgetID_withImage: if not data: texture = vs.GetObject(self.parameters.imageTexture) if texture != 0: vs.DelObject(texture) self.parameters.imageTexture = "" elif self.parameters.imageTexture == "": self.select_image_texture() if self.parameters.imageTexture == "": vs.SetBooleanItem(self.dialog, self.kWidgetID_withImage, False) vs.EnableItem( self.dialog, self.kWidgetID_imageWidthLabel, vs.GetBooleanItem(self.dialog, self.kWidgetID_withImage)) vs.EnableItem( self.dialog, self.kWidgetID_imageWidth, vs.GetBooleanItem(self.dialog, self.kWidgetID_withImage)) vs.EnableItem( self.dialog, self.kWidgetID_imageHeightLabel, vs.GetBooleanItem(self.dialog, self.kWidgetID_withImage)) vs.EnableItem( self.dialog, self.kWidgetID_imageHeight, vs.GetBooleanItem(self.dialog, self.kWidgetID_withImage)) vs.EnableItem( self.dialog, self.kWidgetID_imagePositionLabel, vs.GetBooleanItem(self.dialog, self.kWidgetID_withImage)) vs.EnableItem( self.dialog, self.kWidgetID_imagePosition, vs.GetBooleanItem(self.dialog, self.kWidgetID_withImage)) vs.EnableItem( self.dialog, self.kWidgetID_imageEditButton, vs.GetBooleanItem(self.dialog, self.kWidgetID_withImage)) elif item == self.kWidgetID_imageEditButton: self.select_image_texture() elif item == self.kWidgetID_withFrame: vs.EnableItem(self.dialog, self.kWidgetID_frameWidthLabel, data) vs.EnableItem(self.dialog, self.kWidgetID_frameWidth, data) vs.EnableItem(self.dialog, self.kWidgetID_frameHeightLabel, data) vs.EnableItem(self.dialog, self.kWidgetID_frameHeight, data) vs.EnableItem(self.dialog, self.kWidgetID_frameThicknessLabel, data) vs.EnableItem(self.dialog, self.kWidgetID_frameThickness, data) vs.EnableItem(self.dialog, self.kWidgetID_frameDepthLabel, data) vs.EnableItem(self.dialog, self.kWidgetID_frameDepth, data) vs.EnableItem(self.dialog, self.kWidgetID_frameClassLabel, data) vs.EnableItem(self.dialog, self.kWidgetID_frameClass, data) vs.EnableItem(self.dialog, self.kWidgetID_frameTextureScaleLabel, data) vs.EnableItem(self.dialog, self.kWidgetID_frameTextureScale, data) vs.EnableItem(self.dialog, self.kWidgetID_frameTextureRotationLabel, data) vs.EnableItem(self.dialog, self.kWidgetID_frameTextureRotation, data) elif item == self.kWidgetID_withMatboard: vs.EnableItem(self.dialog, self.kWidgetID_matboardPositionLabel, data) vs.EnableItem(self.dialog, self.kWidgetID_matboardPosition, data) vs.EnableItem(self.dialog, self.kWidgetID_matboardClassLabel, data) vs.EnableItem(self.dialog, self.kWidgetID_matboardClass, data) vs.EnableItem(self.dialog, self.kWidgetID_matboardTextureScaleLabel, data) vs.EnableItem(self.dialog, self.kWidgetID_matboardTextureScale, data) vs.EnableItem(self.dialog, self.kWidgetID_matboardTextureRotatLabel, data) vs.EnableItem(self.dialog, self.kWidgetID_matboardTextureRotat, data) elif item == self.kWidgetID_withGlass: vs.EnableItem(self.dialog, self.kWidgetID_glassPositionLabel, data) vs.EnableItem(self.dialog, self.kWidgetID_glassPosition, data) vs.EnableItem(self.dialog, self.kWidgetID_glassClassLabel, data) vs.EnableItem(self.dialog, self.kWidgetID_glassClass, data) elif item == kOK: self.parameters.pictureName = vs.GetItemText( self.dialog, self.kWidgetID_pictureName) if self.parameters.pictureName == "": vs.AlertInform( "The picture name cannot be empty. Please add the picture name", "", True) item = -1 elif vs.GetObject(self.parameters.pictureName) != 0: vs.AlertInform( "The picture name is already in use. Please change the picture name to avoid a conflict", "", True) item = -1 elif vs.GetBooleanItem(self.dialog, self.kWidgetID_withImage) is False and \ vs.GetBooleanItem(self.dialog, self.kWidgetID_withFrame) is False and \ vs.GetBooleanItem(self.dialog, self.kWidgetID_withMatboard) is False and \ vs.GetBooleanItem(self.dialog, self.kWidgetID_withGlass) is False: vs.AlertInform( "This picture contains no elements. \ Please select at least one of the components for the picture object", "", True) item = -1 else: self.parameters.createSymbol = "{}".format( vs.GetBooleanItem(self.dialog, self.kWidgetID_createSymbol)) # Image settings # =============================================================================================== self.parameters.withImage = "{}".format( vs.GetBooleanItem(self.dialog, self.kWidgetID_withImage)) _, img_width = vs.GetEditReal(self.dialog, self.kWidgetID_imageWidth, 3) self.parameters.imageWidth = "{}\"".format(img_width) _, img_height = vs.GetEditReal(self.dialog, self.kWidgetID_imageHeight, 3) self.parameters.imageHeight = "{}\"".format(img_height) _, img_position = vs.GetEditReal(self.dialog, self.kWidgetID_imagePosition, 3) # self.parameters.imagePosition = "{}\"".format(img_position) self.parameters.imagePosition = str(img_position) texture = vs.GetObject(self.parameters.imageTexture) if texture != 0: self.parameters.imageTexture = "{} Prop Texture".format( self.parameters.pictureName) vs.SetName(texture, self.parameters.imageTexture) # Frame settings # =============================================================================================== self.parameters.withFrame = "{}".format( vs.GetBooleanItem(self.dialog, self.kWidgetID_withFrame)) _, frm_width = vs.GetEditReal(self.dialog, self.kWidgetID_frameWidth, 3) self.parameters.frameWidth = "{}".format(frm_width) _, frm_height = vs.GetEditReal(self.dialog, self.kWidgetID_frameHeight, 3) self.parameters.frameHeight = "{}".format(frm_height) _, frm_thickness = vs.GetEditReal( self.dialog, self.kWidgetID_frameThickness, 3) # self.parameters.frameThickness = "{}".format(frm_thickness) self.parameters.frameThickness = str(frm_thickness) _, frm_depth = vs.GetEditReal(self.dialog, self.kWidgetID_frameDepth, 3) # self.parameters.frameDepth = "{}".format(frm_depth) self.parameters.frameDepth = str(frm_depth) _, self.parameters.frameClass = vs.GetSelectedChoiceInfo( self.dialog, self.kWidgetID_frameClass, 0) _, frm_texture_scale = vs.GetEditReal( self.dialog, self.kWidgetID_frameTextureScale, 1) # self.parameters.frameTextureScale = "{}".format(frm_texture_scale) self.parameters.frameTextureScale = str(frm_texture_scale) _, frm_texture_rotation = vs.GetEditReal( self.dialog, self.kWidgetID_frameTextureRotation, 1) # self.parameters.frameTextureRotation = "{}".format(frm_texture_rotation) self.parameters.frameTextureRotation = str( frm_texture_rotation) # Matboard settings # =============================================================================================== self.parameters.withMatboard = "{}".format( vs.GetBooleanItem(self.dialog, self.kWidgetID_withMatboard)) _, matbrd_position = vs.GetEditReal( self.dialog, self.kWidgetID_matboardPosition, 3) # self.parameters.matboardPosition = "{}".format(matbrd_position) self.parameters.matboardPosition = str(matbrd_position) _, self.parameters.matboardClass = vs.GetSelectedChoiceInfo( self.dialog, self.kWidgetID_matboardClass, 0) _, matbrd_texture_scale = vs.GetEditReal( self.dialog, self.kWidgetID_matboardTextureScale, 1) # self.parameters.matboardTextureScale = "{}".format(matbrd_texture_scale) self.parameters.matboardTextureScale = str( matbrd_texture_scale) _, matbrd_texture_rotation = vs.GetEditReal( self.dialog, self.kWidgetID_matboardTextureRotat, 1) # self.parameters.matboardTextureRotat = "{}".format(matbrd_texture_rotation) self.parameters.matboardTextureRotat = str( matbrd_texture_rotation) # Glass settings # =============================================================================================== self.parameters.withGlass = "{}".format( vs.GetBooleanItem(self.dialog, self.kWidgetID_withGlass)) _, self.parameters.glassPosition = vs.GetEditReal( self.dialog, self.kWidgetID_glassPosition, 3) # self.parameters.glassPosition = "{}".format(self.parameters.glassPosition) self.parameters.glassPosition = str( self.parameters.glassPosition) _, self.parameters.glassClass = vs.GetSelectedChoiceInfo( self.dialog, self.kWidgetID_glassClass, 0) elif item == kCancel: texture = vs.GetObject(self.parameters.imageTexture) if texture != 0: vs.DelObject(texture) self.parameters.imageTexture = "" return item