Friday, July 7, 2017

Set Assembly Code file - Dynamo

Set Assembly Code file - Dynamo:

# Default imports import clr clr.AddReference("RevitAPI") clr.AddReference("RevitNodes") from Autodesk.Revit.DB import * ################################# import Revit ################################# clr.ImportExtensions(Revit.GeometryConversion) ################################# clr.ImportExtensions(Revit.Elements) ################################# # Import DocumentManager and TransactionManager################################## clr.AddReference('RevitServices') ################################# import RevitServices ################################# from RevitServices.Persistence import DocumentManager ######################### from RevitServices.Transactions import TransactionManager ##################### doc = DocumentManager.Instance.CurrentDBDocument ############################# elements = IN[0] ##Elements in the model ##EXPECTS STRINGS FROM EXCEL TO START headers = IN[1] ##Headers for reference data = IN[2] ##Data ###Initialize out=[] outMain=[] outSub=[] found=0 ##Find "MARK" Position from headers for markPos, mark in enumerate(headers): if mark=='Mark': ##Found mark in headers proceed found=1 break ##BREAK loop with current header index if found==1: ##Consider adding additional parameters to key-in on other than mark for element in elements: emark=element.GetParameterValueByName('Mark') for dat in data: if dat[markPos]==emark: outMain=[] for hI, param in enumerate(headers): ##hI count based on header to corresponding data For parameters that are headers in the file outSub=[] try: outSub.append(param) ###ADD PARAMS TO Output list outSub.append(dat[hI]) ###ADD TABS + Data to output list if param == 'ASSET_CONDITION': ###NEED TO LOOK AT TARGET PARAMETERS IN REVIT AND RESET THE TYPE ACCORDING TO THE TARGET PARAMETER DATA TYPE, INT, TXT, etc. element.SetParameterByName(param,int(dat[hI])) ###Attempt set data header/param name, dat[i] corresponding data at index outSub.insert(0,"Success!(INT)") ###If it succeedes report it else: element.SetParameterByName(param,dat[hI]) ###Attempt set data header/param name, dat[i] corresponding data at index outSub.insert(0,"Success!(TXT)") ###If it succeedes report it except: ### If if failed...################################################ if param == "Assembly Code": ##SPECIAL ODD-BALL CASE for SYSTEM TYPE PARAM (Assembly Code)#### try: ##################################Assembly Code = Unifromat scan ele=UnwrapElement(element) ########## #Get the type ###################### (UNIFORMAT TYPE param) elementType = doc.GetElement(ele.GetTypeId()) ###################### # Get the parameter################### parameter = elementType.get_Parameter(BuiltInParameter.UNIFORMAT_CODE) #Set the parameter in a Transaction### TransactionManager.Instance.EnsureInTransaction(doc) parameter.Set(str(dat[hI])) ##FROM THE current DAT line of DATA return the data from the hI Index position in the list #Set the parameter end Transaction### TransactionManager.Instance.TransactionTaskDone() outSub.insert(0,"Success!(UNI)") except: outSub.insert(0,"Failed! (ALL)") outMain.append(outSub) ##Append Parameters success/fail out.append(outMain) out.insert(0,[["****Tab must be 'Sheet1'***************\n****'Mark' in row 1 must be defined****"]]) OUT=out

Python Script node for Notepad.exe. Possible? - Developers - Dynamo

Python Script node for Notepad.exe. Possible? - Developers - Dynamo:




import clr clr.AddReference("RevitAPIUI") from Autodesk.Revit.UI import TaskDialog ##Import task dialog ##from datetime import datetime ##Formatting date time strings for files import time ##Time as in NOW or tiem string format functions import sys ##Validate thie is here and avaiable######### sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\Lib') import subprocess ##Launching asynchronus processess like notepad import os ##Operating system - CASE SENSITIVE msg=IN[0] ##DAta in 0 ##msgbox=TaskDialog ##Task Dialog astr="" ##STR for formatting for i in msg: ##BIG MESSAGE LIST sstr="" ##SUB STRING for j in i: for k in j: sstr=sstr + str(k) + "\t" ##ADD TAB SEPARATORS sstr=sstr + "\n" ##ADD CARRIAGE RETURN to substring astr=astr + sstr + "\n" ##ADD substring to main and spacer carriage return ##Set file name using date-time in C:\TEMP#### fn="C:\\temp\\DynamoError-" + time.strftime("%Y-%m-%dt%H%M%Z") + ".txt" f= open (fn, "w+") ##Open file wor Write f.write(astr) ##Write out ASTR subprocess.Popen('notepad {}'.format(fn)) ##Open the file in Notepad Asynchronously ##msgbox.Show("Message", astr ) ##Will show message dialog in revit - WARNING - Synchronus- script will have to wait. OUT=astr ##Pass formatted string out

Monday, July 3, 2017

TOF Cameras

So I have been thinking for a while- if I had a motion picture or multiple pictures and a special light and a special FILM or CMOS to capture that light- I could measure the reflection of the special light to get an approximation of depth.



Thinking about LIDAR and  fixed sensors - I realized this could be taken a step further- capturing the TOF (Time of flight) of light at different intervals using a MOSFET or similar super-fast action capture device.



Apparently there are similar items on the web called TOF Cameras...



https://www.baslerweb.com/en/support/



Support | Basler:



'via Blog this'

Tuesday, May 9, 2017

RSMEANS Python REGEXP extractions

Attribute VB_Name = "RSUnits"
Option Explicit
''Constants for reference of unit types in RSMEANS
'' Floor, concrete, slab form, open web bar joist @ 2' OC, on W beam and wall, 30'x30' bay, 29" deep, 65 PSF superimposed load, 110 PSF total load, for columns add
Public Const VBQT = """"

''these use named regexp returns based in python
''Public Const Regex_BAY+PYTHON = "(?:(?P\d{1,})((?P\'|\" & VBQT & "|ft|in))\W{0,}x\W{0,}(?P\d{1,})(?P\'|\" & VBQT & "|ft|in)\W{0,}bay)"
Public Const Regex_BAY = "(?:([\d\.]{1,})((\'|\" & VBQT & "|ft|in))\W{0,}x\W{0,}(\d{1,})(\'|\" & VBQT & "|ft|in)\W{0,}bay)"
Public Const Regex_Addon = "(?:for\W{0,}(?P\b.+\b)\W{0,}add)\W{0,}"
''Public Const Regex_SPACE+python = "(?:.+,(?P.+?)(\@\W{0,}(?P\d{1,})((?P\'|\" & VBQT & "|ft|in)\W{0,}oc)))"
Public Const Regex_SPACE = "(?:.+,(.+?)(\@\W{0,}([\d\.]{1,})((\'|\" & VBQT & "|ft|in)\W{0,}oc)))"
Public Const Regex_SPAN = "(?:.+,(.+?)(\@\W{0,}([\d\.]{1,})((\'|\" & VBQT & "|ft|in)\W{0,}span)))"
''Public Const Regex_DEEP+PYTHON  = "(?:(?P\d{1,})(?P\'|\" & VBQT & "|ft|in)\W{0,}deep)"
Public Const Regex_DEEP = "(?:([\d\.]{1,})(\'|\" & VBQT & "|ft|in)\W{0,}deep)"
Public Const Regex_LOAD = "(?:(?P\d{1,})\W{0,}(?P(P[S|L]F))\W{0,}(?P\w{1,12})\W{0,}load)"

'' full regexp with names regexp =  watch for VBQTs!
'' (?:(?P\d{1,})((?P\'|\"|ft|in))\W{0,}x\W{0,}(?P\d{1,})(?P\'|\"|ft|in)\W{0,}bay)|(?:for\W{0,}(?P\b.+\b)\W{0,}add)\W{0,}|(?:.+,(?P.+?)(\@\W{0,}(?P\d{1,})((?P\'|\"|ft|in)\W{0,}oc)))|(?:(?P\d{1,})(?P\'|\"|ft|in)\W{0,}deep)|(?:(?P\d{1,})\W{0,}(?P(P[S|L]F))\W{0,}(?P\w{1,12})\W{0,}load)

Type Units
    BAY_X As Integer
    BAY_Y As Integer
    BAY_X_UNIT As String
    BAY_Y_UNIT As String
End Type
Function RSM_Val(strValue As String, Optional strType As String) As Variant
Dim rangeCaller As Range
Dim reg As New Regexp
Dim strl As String
Dim ret As MatchCollection

Dim strNumberFormat As String

''only returns one value at a time so only need to track one measurement except wxd for 'bay'
Dim Height As Single
Dim Width As Single
Dim Depth As Single
Dim UNIT As String


Dim Found As Boolean        ''for control over formatting
Found = False

    strl = LCase(strValue)
    strType = LCase(strType)
    Set rangeCaller = Application.Caller
   
    Select Case strType
        Case "bay"
            reg.Pattern = RSUnits.Regex_BAY
       
            Set ret = reg.Execute(strValue)
            If ret.Count > 0 Then
                Width = ret.Item(0).SubMatches.Item(0)
                If ret.Item(0).SubMatches.Item(1) = VBQT Then ret.Item(0).SubMatches.Item(1) = "''"  ''may not be needed returning text.
                Depth = ret.Item(0).SubMatches.Item(3)
                If ret.Item(0).SubMatches.Item(4) = VBQT Then ret.Item(0).SubMatches.Item(4) = "''"  ''may not be needed returning text.
               
                RSM_Val = Width & ret.Item(0).SubMatches.Item(1) & " x " & Depth & ret.Item(0).SubMatches.Item(4)
                UNIT = "General"
               
                rangeCaller.Cells(1, 1).HorizontalAlignment = xlCenter
                rangeCaller.Cells(1, 1).VerticalAlignment = xlCenter
                Found = True
            End If
        Case "bayx"
            reg.Pattern = RSUnits.Regex_BAY
       
            Set ret = reg.Execute(strValue)
            If ret.Count > 0 Then
                Width = ret.Item(0).SubMatches.Item(0)
                UNIT = ret.Item(0).SubMatches.Item(1)
                Depth = ret.Item(0).SubMatches.Item(3)
                strNumberFormat = "00" & VBQT & UNIT & VBQT
               
                RSM_Val = Width
               
                rangeCaller.Cells(1, 1).HorizontalAlignment = xlRight
                Found = True
            End If
        Case "bayy"
            reg.Pattern = RSUnits.Regex_BAY
       
            Set ret = reg.Execute(strValue)
            If ret.Count > 0 Then
                Depth = ret.Item(0).SubMatches.Item(3)
                UNIT = ret.Item(0).SubMatches.Item(4)
                RSM_Val = Depth
                rangeCaller.Cells(1, 1).HorizontalAlignment = xlRight
                Found = True
            End If
           
        Case "deep"
            reg.Pattern = RSUnits.Regex_DEEP
       
            Set ret = reg.Execute(strValue)
            If ret.Count > 0 Then
                Height = ret.Item(0).SubMatches.Item(0)
                UNIT = ret.Item(0).SubMatches.Item(1)
                RSM_Val = Height
                Found = True
            End If
       
    End Select

    If Found = True Then                                                '''Reset formatting
        FormatCell Application.Caller, UNIT
    Else                                                                ''''reset cell to general formatting
        RSM_Val = ""
        rangeCaller.NumberFormat = "General"
        rangeCaller.HorizontalAlignment = xlTop
        rangeCaller.VerticalAlignment = xlLeft
    End If
       
End Function

Private Sub FormatCell(xr As Range, UNIT As String)
Select Case UNIT
    Case VBQT, "''" ''inches
        UNIT = "00.00" & "''"
    Case "'"
        UNIT = "00" & "'"
    Case Else
        UNIT = "General"
End Select
    Sheet1.strNumberFormat = UNIT   ''trick to attempt force override on sheet value change
    xr.NumberFormat = UNIT
End Sub