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 execute(): global file, dialog_id, plugin_handle # check if Lighting Device plugin existing plugin_handle = vs.GetObject(PLUGIN_NAME) device_list = [] vs.ForEachObject(lambda h: device_list.append(h), "(PON='Lighting Device')") if device_list: # create dialog from external file dialog_id = CreateDialog() if vs.RunLayoutDialog(dialog_id, dialog_handler) == kOK: # get platform type for difference file directory style err, dir_path = vs.GetFolder('Select a Folder') file_name, _ = os.path.splitext(vs.GetFName()) file_name = file_name + '.csv' if err == 0: # create file with open(dir_path + file_name, 'w') as file: # main procedure for write data for criteria in cCriteria: vs.ForEachObject(do_it, criteria) vs.AlrtDialog('File: \n' + file_name + ' \n\nCreated in:\n' + dir_path) else: vs.AlrtDialog('Lighting Device not found')
def __init__(self, handle_or_name): """ :type handle_or_name: vs.Handle | str """ # The name can be changed during script execution, the handle can't! # So we only save the handle, gotten by the parameter, or found by it's name! self.__handle = handle_or_name if not isinstance( handle_or_name, str) else vs.GetObject(handle_or_name)
def GetTexture(self): if self.__fRefNum <= 0: textureName = self.__CreateTexture() else: textureName = vs.Index2Name(self.__fRefNum) self.__fTextureHand = vs.GetObject(textureName) self.__SetColor() self.__SetOpacity(vs.GetRecord(self.__fTextureHand, 1)) return self.__fRefNum, textureName
def get(handle_or_name) -> int: """Gets the object type based on the handle or name. In VW, both are keys, but name isn't always provided. Also, some vs calls work with handles, others with names. :type handle_or_name: vs.Handle | str :returns: None if the handle or name doesn't references an actual object. """ return vs.GetTypeN( vs.GetObject(handle_or_name) if isinstance(handle_or_name, str ) else handle_or_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 main(): # Define globals global gObjName, gObjHandle, gRecordHandle, gWallHandle ok, gObjName, gObjHandle, gRecordHandle, gWallHandle = vs.GetCustomObjectInfo( ) if gObjHandle == vs.Handle(): gObjName = 'Window with Curtains' gObjHandle = vs.GetObject(gObjName) # get the format # Get event theEvent, theEventData = vs.vsoGetEventInfo() if theEvent == Constants.kObjOnInitXProperties: ok = vs.SetObjPropVS(Constants.kObjXPropPreference, True) ok = vs.SetObjPropVS(Constants.kObjXPropHasUIOverride, True) ok = vs.SetObjPropVS(Constants.kObjXHasCustomWidgetVisibilities, True) InitProps() elif theEvent == Constants.kObjOnWidgetPrep: UpdateParams() # to do: set visibilities # ... # this is very important! this is how the system knows we've handled this vs.vsoSetEventResult(Constants.kObjectEventHandled) elif theEvent == Constants.kParametricPreference: #Call the preferences window as the object is created or prefs button is clicked CurtWindowDlg.Dialog(gObjHandle) elif theEvent == Constants.kObjOnObjectUIButtonHit: OnButton(theEventData) elif theEvent == Constants.kParametricRecalculate: #Check the values, which the user enters in the OIP CheckValues() Reset()
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 handle(self) -> vs.Handle: """Will return the instance or definition handle of an object plugin. """ succeeded, name, plugin_handle, record_handle, wall_handle = vs.GetCustomObjectInfo( ) return plugin_handle if succeeded else vs.GetObject(self.name)
def get_worksheet_rows( self, log_file: IO) -> Generator[PictureParameters, None, None]: """ :return: """ picture = PictureParameters() if self.connected and self.settings.excelSheetName: query_string = 'SELECT * FROM [{}] WHERE [{}] = \'{}\';'.format( self.settings.excelSheetName, self.settings.excelCriteriaSelector, self.settings.excelCriteriaValue) cursor = self.workbook.cursor() if cursor: cursor.execute(query_string) rows = cursor.fetchall() for row in rows: image_message = "" frame_message = "" matboard_message = "" glass_message = "" valid_picture = True name = row[self.settings.imageTextureSelector.lower()] picture_name = to_string(name) if not picture_name: log_message = "UNKNOWN [Error] - Picture name not found\n" log_file.write(log_message) picture.pictureName = "" yield picture else: picture.pictureName = picture_name if picture.pictureName == "Caricature1": stop = True # Obtain image parameters if self.settings.withImageSelector == "-- Manual": picture.withImage = self.settings.pictureParameters.withImage else: cell_value = row[ self.settings.withImageSelector.lower()] if cell_value and cell_value != "" and cell_value != "False" and cell_value != "No": picture.withImage = "True" else: picture.withImage = "False" if picture.withImage == "True": cell_value = row[ self.settings.imageWidthSelector.lower()] valid, value = vs.ValidNumStr( cell_value) if isinstance( cell_value, str) else [True, cell_value] if valid and value is not None: picture.imageWidth = str(round(value, 3)) else: image_message += "- Invalid Image Width ({})".format( cell_value) valid_picture = False cell_value = row[ self.settings.imageHeightSelector.lower()] valid, value = vs.ValidNumStr( cell_value) if isinstance( cell_value, str) else [True, cell_value] if valid and value is not None: picture.imageHeight = str(round(value, 3)) else: image_message += "- Invalid Image Height ({})".format( cell_value) valid_picture = False if self.settings.imagePositionSelector == "-- Manual": cell_value = self.settings.pictureParameters.imagePosition else: cell_value = row[self.settings. imagePositionSelector.lower()] valid, value = vs.ValidNumStr( cell_value) if isinstance( cell_value, str) else [True, cell_value] if valid and value is not None: picture.imagePosition = str(round(value, 3)) else: image_message += "- Invalid Image Position ({})".format( cell_value) valid_picture = False # Obtain frame parameters if self.settings.withFrameSelector == "-- Manual": picture.withFrame = self.settings.pictureParameters.withFrame else: cell_value = row[ self.settings.withFrameSelector.lower()] if cell_value is not None and cell_value != "" and cell_value != "False" and cell_value != "No": picture.withFrame = "True" else: picture.withFrame = "False" if picture.withFrame == "True": cell_value = row[ self.settings.frameWidthSelector.lower()] valid, value = vs.ValidNumStr( cell_value) if isinstance( cell_value, str) else [True, cell_value] if valid and value is not None: picture.frameWidth = str(round(value, 3)) else: frame_message += "- Invalid Frame Width ({})".format( cell_value) valid_picture = False cell_value = row[ self.settings.frameHeightSelector.lower()] valid, value = vs.ValidNumStr( cell_value) if isinstance( cell_value, str) else [True, cell_value] if valid and value is not None: picture.frameHeight = str(round(value, 3)) else: frame_message += "- Invalid Frame Height ({})".format( cell_value) valid_picture = False if self.settings.frameThicknessSelector == "-- Manual": cell_value = self.settings.pictureParameters.frameThickness else: cell_value = row[ self.settings.pictureParameters. frameThicknessSelector.lower()] valid, value = vs.ValidNumStr( cell_value) if isinstance( cell_value, str) else [True, cell_value] if valid and value is not None: picture.frameThickness = str(round(value, 3)) else: frame_message += "- Invalid Frame Thickness ({})".format( cell_value) valid_picture = False if self.settings.frameDepthSelector == "-- Manual": cell_value = self.settings.pictureParameters.frameDepth else: cell_value = row[ self.settings.frameDepthSelector.lower()] valid, value = vs.ValidNumStr( cell_value) if isinstance( cell_value, str) else [True, cell_value] if valid and value is not None: picture.frameDepth = str(round(value, 3)) else: frame_message += "- Invalid Frame Depth ({})".format( cell_value) valid_picture = False if self.settings.frameClassSelector == "-- Manual": picture.frameClass = self.settings.pictureParameters.frameClass else: cell_value = row[ self.settings.frameClassSelector.lower()] new_class = vs.GetObject(cell_value) if new_class == 0: if self.settings.createMissingClasses: active_class = vs.ActiveClass() vs.NameClass(cell_value) vs.NameClass(active_class) picture.frameClass = cell_value else: frame_message += "- No such Frame Class ({})".format( cell_value) valid_picture = False else: picture.frameClass = cell_value if self.settings.frameTextureScaleSelector == "-- Manual": cell_value = self.settings.pictureParameters.frameTextureScale else: cell_value = row[ self.settings.frameTextureScaleSelector. lower()] valid, value = vs.ValidNumStr( cell_value) if isinstance( cell_value, str) else [True, cell_value] if valid and value is not None: picture.frameTextureScale = str(round( value, 3)) else: frame_message += "- Invalid Frame Texture Scale ({})".format( cell_value) valid_picture = False if self.settings.frameTextureRotationSelector == "-- Manual": cell_value = self.settings.pictureParameters.frameTextureRotation else: cell_value = row[ self.settings.frameTextureRotationSelector. lower()] valid, value = vs.ValidNumStr( cell_value) if isinstance( cell_value, str) else [True, cell_value] if valid and value is not None: picture.frameTextureRotation = str( round(value, 3)) else: frame_message += "- Invalid Frame Texture Rotation ({})".format( cell_value) valid_picture = False # Obtain matboard parameters if self.settings.withMatboardSelector == "-- Manual": picture.withMatboard = self.settings.pictureParameters.withMatboard else: cell_value = row[ self.settings.withMatboardSelector.lower()] if cell_value and cell_value != "" and cell_value != "False" and cell_value != "No": picture.withMatboard = "True" else: picture.withMatboard = "False" if picture.withMatboard == "True": cell_value = row[ self.settings.frameWidthSelector.lower()] valid, value = vs.ValidNumStr( cell_value) if isinstance( cell_value, str) else [True, cell_value] if valid and value is not None: picture.frameWidth = str(round(value, 3)) else: frame_message += "- Invalid Frame Width (needed for Matboard) ({})".format( cell_value) valid_picture = False cell_value = row[ self.settings.frameHeightSelector.lower()] valid, value = vs.ValidNumStr( cell_value) if isinstance( cell_value, str) else [True, cell_value] if valid and value is not None: picture.frameHeight = str(round(value, 3)) else: frame_message += "- Invalid Frame Height (needed for Matboard) ({})".format( cell_value) valid_picture = False cell_value = row[ self.settings.windowWidthSelector.lower()] valid, value = vs.ValidNumStr( cell_value) if isinstance( cell_value, str) else [True, cell_value] if valid and value is not None: picture.windowWidth = str(round(value, 3)) else: if picture.withImage == "True": picture.windowWidth = picture.imageWidth matboard_message += "- Missing window width, using image width instead" else: matboard_message += "- Invalid Window Width ({})".format( cell_value) valid_picture = False cell_value = row[ self.settings.windowHeightSelector.lower()] valid, value = vs.ValidNumStr( cell_value) if isinstance( cell_value, str) else [True, cell_value] if valid and value is not None: picture.windowHeight = str(round(value, 3)) else: if picture.withImage == "True": picture.windowHeight = picture.imageHeight matboard_message += "- Missing window height, using image height instead" else: matboard_message += "- Invalid Window Height ({})".format( cell_value) valid_picture = False if self.settings.matboardPositionSelector == "-- Manual": cell_value = self.settings.pictureParameters.matboardPosition else: cell_value = row[ self.settings.matboardPositionSelector. lower()] valid, value = vs.ValidNumStr( cell_value) if isinstance( cell_value, str) else [True, cell_value] if valid and value is not None: picture.matboardPosition = str(round(value, 3)) else: matboard_message += "- Invalid Matboard Position ({})".format( cell_value) valid_picture = False if self.settings.matboardClassSelector == "-- Manual": picture.matboardClass = self.settings.pictureParameters.matboardClass else: cell_value = row[self.settings. matboardClassSelector.lower()] new_class = vs.GetObject(cell_value) if new_class == 0: if self.settings.createMissingClasses: active_class = vs.ActiveClass() vs.NameClass(cell_value) vs.NameClass(active_class) picture.matboardClass = cell_value else: matboard_message += "- No such Matboard Class ({})".format( cell_value) valid_picture = False else: picture.matboardClass = cell_value if self.settings.matboardTextureScaleSelector == "-- Manual": cell_value = self.settings.pictureParameters.matboardTextureScale else: cell_value = row[ self.settings.matboardTextureScaleSelector. lower()] valid, value = vs.ValidNumStr( cell_value) if isinstance( cell_value, str) else [True, cell_value] if valid and value is not None: picture.matboardTextureScale = str( round(value, 3)) else: matboard_message += "- Invalid Matboard Texture Scale ({})".format( cell_value) valid_picture = False if self.settings.matboardTextureRotatSelector == "-- Manual": cell_value = self.settings.pictureParameters.matboardTextureRotat else: cell_value = row[ self.settings.matboardTextureRotatSelector. lower()] valid, value = vs.ValidNumStr( cell_value) if isinstance( cell_value, str) else [True, cell_value] if valid and value is not None: picture.matboardTextureRotat = str( round(value, 3)) else: matboard_message += "- Invalid Matboard Texture Rotation ({})".format( cell_value) valid_picture = False # Obtain glass parameters if self.settings.withGlassSelector == "-- Manual": picture.withGlass = self.settings.pictureParameters.withGlass else: cell_value = row[ self.settings.withGlassSelector.lower()] if cell_value and cell_value != "" and cell_value != "False" and cell_value != "No": picture.withGlass = "True" else: picture.withGlass = "False" if picture.withGlass == "True": if self.settings.glassPositionSelector == "-- Manual": cell_value = self.settings.pictureParameters.glassPosition else: cell_value = row[self.settings. glassPositionSelector.lower()] valid, value = vs.ValidNumStr( cell_value) if isinstance( cell_value, str) else [True, cell_value] if valid and value is not None: picture.glassPosition = str(round(value, 3)) else: glass_message += "- Invalid Glass Position ({})".format( cell_value) valid_picture = False if self.settings.glassClassSelector == "-- Manual": picture.glassClass = self.settings.pictureParameters.glassClass else: cell_value = row[ self.settings.glassClassSelector.lower()] new_class = vs.GetObject(picture.glassClass) if new_class == 0: if self.settings.createMissingClasses: active_class = vs.ActiveClass() vs.NameClass(cell_value) vs.NameClass(active_class) picture.glassClass = cell_value else: glass_message += "- No such Glass Class ({})".format( cell_value) valid_picture = False else: picture.glassClass = cell_value # Obtain symbol information if self.settings.symbolCreateSymbol == "True": picture.createSymbol = "True" if self.settings.symbolFolderSelector == "-- Manual": picture.symbolFolder = self.settings.symbolFolder else: folder_name = row[ self.settings.symbolFolderSelector.lower()] if folder_name: picture.symbolFolder = "{} Folder".format( folder_name.translate({ ord(c): '_' for c in string.whitespace }).replace("__", "_")) # picture.symbolFolder = "Picture folder - {}".format(folder_name.translate({ord(c): '_' for c in string.whitespace}).replace("__", "_")) else: picture.createSymbol = "False" picture.symbolFolder = "" # Obtain Class information if self.settings.classAssignPictureClass == "True": if self.settings.classClassPictureSelector == "-- Manual": picture.pictureClass = self.settings.pictureParameters.pictureClass else: picture.pictureClass = row[ self.settings.classClassPictureSelector. lower()] # Obtain Metadata information if self.settings.metaImportMetadata == "True": if picture.withImage == "True": self.settings.pictureRecord.imageSize = "Height: {}, Width: {}".format( picture.imageHeight, picture.imageWidth) if picture.withFrame == "True" or picture.withMatboard == "True": self.settings.pictureRecord.frameSize = "Height: {}, Width: {}".format( picture.frameHeight, picture.frameWidth) if picture.withMatboard == "True": self.settings.pictureRecord.windowSize = "Height: {}, Width: {}".format( picture.windowHeight, picture.windowWidth) if self.settings.metaArtworkTitleSelector != "-- Don't Import": self.settings.pictureRecord.artworkTitle = row[ self.settings.metaArtworkTitleSelector. lower()] if self.settings.metaAuthorNameSelector != "-- Don't Import": self.settings.pictureRecord.authorName = row[ self.settings.metaAuthorNameSelector.lower( )] if self.settings.metaArtworkCreationDateSelector != "-- Don't Import": self.settings.pictureRecord.artworkCreationDate = make_year_string( row[self.settings. metaArtworkCreationDateSelector.lower( )]) if self.settings.metaArtworkMediaSelector != "-- Don't Import": self.settings.pictureRecord.artworkMedia = row[ self.settings.metaArtworkMediaSelector. lower()] # if self.settings.metaTypeSelector != "-- Don't Import": # self.settings.pictureRecord. = row[self.settings.metaTypeSelector.lower()] if self.settings.metaRoomLocationSelector != "-- Don't Import": self.settings.pictureRecord.roomLocation = row[ self.settings.metaRoomLocationSelector. lower()] if self.settings.metaArtworkSourceSelector != "-- Don't Import": self.settings.pictureRecord.artworkSource = row[ self.settings.metaArtworkSourceSelector. lower()] if self.settings.metaRegistrationNumberSelector != "-- Don't Import": self.settings.pictureRecord.registrationNumber = row[ self.settings. metaRegistrationNumberSelector.lower()] if self.settings.metaAuthorBirthCountrySelector != "-- Don't Import": self.settings.pictureRecord.authorBirthCountry = row[ self.settings. metaAuthorBirthCountrySelector.lower()] if self.settings.metaAuthorBirthDateSelector != "-- Don't Import": self.settings.pictureRecord.authorBirthDate = make_year_string( row[self.settings. metaAuthorBirthDateSelector.lower()]) if self.settings.metaAuthorDeathDateSelector != "-- Don't Import": self.settings.pictureRecord.authorDeathDate = make_year_string( row[self.settings. metaAuthorDeathDateSelector.lower()]) if self.settings.metaDesignNotesSelector != "-- Don't Import": self.settings.pictureRecord.designNotes = row[ self.settings.metaDesignNotesSelector. lower()] if self.settings.metaExhibitionMediaSelector != "-- Don't Import": self.settings.pictureRecord.exhibitionMedia = row[ self.settings.metaExhibitionMediaSelector. lower()] if not valid_picture: log_message = "{} * [Error]".\ format(picture_name) + image_message + frame_message + matboard_message + glass_message + "\n" log_file.write(log_message) picture.pictureName = "" yield picture cursor.close()
def create_placeholder(name: str): if vs.GetObject(name) is None: vs.BeginSym(name) vs.EndSym() vs.SetObjectVariableBoolean(vs.GetObject(name), 900, False) return SymbolDefinition(vs.GetObject(name))
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
def create_placeholder(name: str): if vs.GetObject(name) is None: vs.NewField(name, 'placeholder', '', 4, 0) vs.SetObjectVariableBoolean(vs.GetObject(name), 900, False) return RecordDefinition(vs.GetObject(name))
def get_by_name(name: str): """OBSOLETE. Use ObjectRepository().get(handle_or_name) from object_base instead. """ obj_handle = vs.GetObject(name) obj_handle = obj_handle if vs.GetTypeN(obj_handle) == 16 else None # 16 = symbol definition. return SymbolDefinition(obj_handle) if obj_handle is not None else None
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 add_to_list(h): symbol_name = vs.GetRField(h, 'Lighting Device', 'Symbol Name') symbol_list.add(vs.GetObject(symbol_name))
def _set_vector_fill(self, value): """ :type value: T <= AbstractVectorFill """ vs.SetObjectVariableLongInt(vs.GetObject(self._clazz_name), 695, vs.Name2Index(value.name) * -1)