def drawOpening(distance, length, block=0): if block == 1 and rs.IsBlock("window") == False: util.initWindowBlock() if block == 2 and rs.IsBlock("door") == False: util.initDoorBlock() if not rs.IsLayer("Axis"): util.initCaadLayer("Axis") twoLines = findTwoParallelLines() if not twoLines: return 0 pi, linei, linej = twoLines if not linej: return 0 pj = linej.CurveGeometry.Line.ClosestPoint(pi, False) oldLockMode = rs.LayerLocked("Axis", True) # side=0 start from startPoint , side=1 start from endPoint if rs.Distance(linei.CurveGeometry.Line.From, pi) <= rs.Distance( pi, linei.CurveGeometry.Line.To): side = 0 else: side = 1 # direct: # 0 | 1 # ------- # 2 | 3 vji = rs.VectorCreate(pj, pi) vi = linei.CurveGeometry.Line.Direction angle = rs.Angle((0, 0, 0), rs.VectorRotate(vji, -rs.Angle((0, 0, 0), vi)[0], (0, 0, 1))) if abs(angle[0] - 90) < sc.doc.ModelAbsoluteTolerance: line0 = linei line1 = linej if side == 0: direct = 2 else: direct = 3 elif abs(angle[0] + 90) < sc.doc.ModelAbsoluteTolerance: line0 = linej line1 = linei if side == 0: direct = 0 else: direct = 1 dl = DoubleLine(line0.CurveGeometry.Line, line1.CurveGeometry.Line) newLayer = rs.ObjectLayer(line0.Id) oldLayer = rs.CurrentLayer(newLayer) dl.drawOpening(distance, length, side, block, direct) rs.DeleteObject(line0.Id) rs.DeleteObject(line1.Id) rs.CurrentLayer(oldLayer) rs.LayerLocked("Axis", oldLockMode)
def CreateDesignOption(): objs = rs.GetObjects("Select objects to create design option with", preselect=True) if objs is None: return None try: date = utils.GetDatePrefix() origName = date + '_OPTION_00' defaultName = origName for i in range(100): defaultName = utils.UpdateString(defaultName) if origName == defaultName: break if rs.IsBlock(defaultName) == False: break looping = True while looping: designOptionName = rs.StringBox("Design Option Name", defaultName, "Create Design Option") if designOptionName is None: return None if rs.IsBlock(designOptionName): print "Block name already exists" elif len(designOptionName) == 0: print "Must specify a name" else: looping = False block = rs.AddBlock(objs, (0, 0, 0), designOptionName, True) blockInstance = rs.InsertBlock(designOptionName, (0, 0, 0)) #Add user text rs.SetUserText(blockInstance, 'Design Option History', designOptionName) #Ensure 3_DESIGN OPTIONS already exists layers.AddLayerByNumber(3000, False) #Create new layer parentLayer = layers.GetLayerNameByNumber(3000) designOptionLayer = rs.AddLayer(parentLayer + "::" + designOptionName, color=utils.GetRandomColor()) rs.ObjectLayer(blockInstance, designOptionLayer) utils.SaveFunctionData('Blocks-Create Design Option', [__version__, designOptionName]) return True except: print "Failed to create design option" utils.SaveFunctionData('Blocks-Create Design Option', [__version__, '', 'Failed']) return None
def MakeBlockUniqueButton(): try: block = rs.GetObject("Select block to make unique", rs.filter.instance, preselect=True) if block is None: return defaultName = utils.UpdateString(rs.BlockInstanceName(block)) looping = True while looping: newName = rs.StringBox("Enter new block name", default_value=defaultName, title='MakeUnique') if newName is None: return if rs.IsBlock(newName): print "Block name already exists" elif len(newName) == 0: print "Must specify a name" else: looping = False if newName is None: return rs.EnableRedraw(False) newBlock = MakeBlockUnique(block, newName) rs.EnableRedraw(True) rs.SelectObject(newBlock) return True except: return False
def RenameBlockButton(): try: block = rs.GetObject("Select block to rename", filter=4096, preselect=True) #Default Name try: number = int(rs.BlockInstanceName(block).split('_')[-1]) number += 1 if len(str(number)) < 2: numString = '0' + str(number) else: numString = str(number) except: numString = '01A' defaultName = GetDatePrefix() + "_OPTION_" + numString looping = True while looping: newName = rs.StringBox("Enter new block name", default_value=defaultName, title='Rename Block') if newName is None: return if rs.IsBlock(newName): print "Block name already exists" elif len(newName) == 0: print "Must specify a name" pass else: looping = False return rs.RenameBlock(rs.BlockInstanceName(block), newName) except: return None
def TryLoadBlock(type, name): if type == '3D People': typeFolder = 'People 3D Folder' elif type == '2D People': typeFolder = 'People 2D Folder' elif type == '2D Trees': typeFolder = 'Vegetation 2D Folder' elif type == '3D Trees': typeFolder = 'Vegetation 3D Folder' elif type == '3D Vehicles': typeFolder = 'Vehicle 3D Folder' if rs.IsBlock(name): return True else: folderpath = fileLocations[typeFolder] files = os.listdir(folderpath) for file in files: if os.path.splitext(file)[1] == '.3dm': shortName = os.path.splitext(file)[0] if shortName == name: filepath = os.path.join(folderpath, file) filepath2 = '"' + filepath + '"' if os.path.isfile(filepath): rs.Command('-_Insert ' + filepath2 + ' B 0 1 0 ', False) objs = rs.SelectedObjects() for obj in objs: rs.DeleteObject(obj) return True
def _definition_exists(cls): """Returns: value boolean. True, if a frame block definition exists. False, otherwise """ block_name = s.Settings.frame_name value = rs.IsBlock(block_name) return value
def _definition_exists(cls): """Returns: value boolean. True, if an arrow definition exists. False, otherwise """ arrow_name = s.Settings.arrow_name value = rs.IsBlock(arrow_name) return value
def ReplicateBlock(blockObj): #Copy block copiedBlock = rs.CopyObject(blockObj) #Get new block name origName = rs.BlockInstanceName(blockObj) defaultName = origName for i in range(100): defaultName = utils.UpdateString(defaultName) if origName == defaultName: break if rs.IsBlock(defaultName) == False: break looping = True while looping: newBlockName = rs.StringBox("Enter new block name", default_value=defaultName, title='Iterate Design Option') if newBlockName is None: rs.DeleteObject(copiedBlock) return if rs.IsBlock(newBlockName): print "Block name already exists" elif len(newBlockName) == 0: print "Must specify a name" else: looping = False if newBlockName is None: rs.DeleteObject(copiedBlock) return #Get previous base point xform = rs.BlockInstanceXform(copiedBlock) basePoint = rs.BlockInstanceInsertPoint(copiedBlock) #Explode block objsInside = rs.ExplodeBlockInstance(copiedBlock) rs.AddBlock(objsInside, basePoint, newBlockName, True) #Create new block instance = rs.InsertBlock2(newBlockName, xform) return instance
def test___init__(): method_name = '__init__' try_name = 'try_good' g.Grammar.clear_all() nakata = n.Nakata() actual_value = rs.IsBlock('zigzag') expected_value = True if not actual_value == expected_value: u.Utilities.print_test_error_message(method_name, try_name, expected_value, actual_value)
def _get_number_of_frames(cls, layer_name): """Receives: layer_name str. The name of the layer Returns: n int. The number of frame instances on the layer """ frame_name = s.Settings.frame_name if not rs.IsBlock(frame_name): n = 0 else: frame_instance_guids = rs.BlockInstances(frame_name) n = 0 for guid in frame_instance_guids: if cls._contains_guid(guid, layer_name): n = n + 1 return n
def _insert_other_block(other_block_name, layer_name, position): if not rs.IsBlock(other_block_name): _define_other_block() rs.CurrentLayer(layer_name) rs.InsertBlock(other_block_name, position) rs.CurrentLayer(s.Settings.default_layer_name)
def main(): if not rs.IsBlock("SomeBlockName"): print "Missing block definition: SomeBlockName"