@@ -49,16 +49,16 @@ public override void AddSender(string args)
4949 ISelectionFilter filter = JsonConvert . DeserializeObject ( JsonConvert . SerializeObject ( client . filter ) , GetFilterType ( client . filter . Type . ToString ( ) ) ) ;
5050 GetSelectionFilterObjects ( filter , client . _id . ToString ( ) , client . streamId . ToString ( ) ) ;
5151
52- SpeckleTelemetry . RecordStreamCreated ( "Revit" ) ;
52+ SpeckleTelemetry . RecordStreamCreated ( "Revit" ) ;
5353 }
5454
5555 public override void UpdateSender ( string args )
5656 {
5757 var client = JsonConvert . DeserializeObject < dynamic > ( args ) ;
58- var index = ClientListWrapper . clients . FindIndex ( cl => ( string ) cl . _id == ( string ) client . _id ) ;
58+ var index = ClientListWrapper . clients . FindIndex ( cl => ( string ) cl . _id == ( string ) client . _id ) ;
5959 ClientListWrapper . clients [ index ] = client ;
6060
61- var myStream = LocalState . FirstOrDefault ( st => st . StreamId == ( string ) client . streamId ) ;
61+ var myStream = LocalState . FirstOrDefault ( st => st . StreamId == ( string ) client . streamId ) ;
6262 myStream . Name = ( string ) client . name ;
6363
6464 Queue . Add ( new Action ( ( ) =>
@@ -76,17 +76,17 @@ public override void UpdateSender(string args)
7676 ISelectionFilter filter = JsonConvert . DeserializeObject ( JsonConvert . SerializeObject ( client . filter ) , GetFilterType ( client . filter . Type . ToString ( ) ) ) ;
7777 GetSelectionFilterObjects ( filter , client . _id . ToString ( ) , client . streamId . ToString ( ) ) ;
7878
79- SpeckleTelemetry . RecordStreamUpdated ( "Revit" ) ;
79+ SpeckleTelemetry . RecordStreamUpdated ( "Revit" ) ;
8080 }
8181
8282 // NOTE: This is actually triggered when clicking "Push!"
8383 // TODO: Orchestration
8484 // Create buckets, send sequentially, notify ui re upload progress
8585 // NOTE: Problems with local context and cache: we seem to not sucesffuly pass through it
8686 // perhaps we're not storing the right sent object (localcontext.addsentobject)
87- public override void PushSender ( string args )
87+ public override void PushSender ( string args )
8888 {
89- var client = JsonConvert . DeserializeObject < dynamic > ( args ) ;
89+ var client = JsonConvert . DeserializeObject < dynamic > ( args ) ;
9090
9191 //if it's a category or property filter we need to refresh the list of objects
9292 //if it's a selection filter just use the objects that were stored previously
@@ -95,138 +95,138 @@ public override void PushSender( string args )
9595
9696 objects = GetSelectionFilterObjects ( filter , client . _id . ToString ( ) , client . streamId . ToString ( ) ) ;
9797
98- var apiClient = new SpeckleApiClient ( ( string ) client . account . RestApi ) { AuthToken = ( string ) client . account . Token } ;
98+ var apiClient = new SpeckleApiClient ( ( string ) client . account . RestApi ) { AuthToken = ( string ) client . account . Token } ;
9999
100100 var convertedObjects = new List < SpeckleObject > ( ) ;
101101 var placeholders = new List < SpeckleObject > ( ) ;
102102
103- var units = CurrentDoc . Document . GetUnits ( ) . GetFormatOptions ( UnitType . UT_Length ) . DisplayUnits . ToString ( ) . ToLower ( ) . Replace ( "dut_" , "" ) ;
104- InjectScaleInKits ( GetScale ( units ) ) ; // this is used for feet to sane units conversion.
103+ var units = CurrentDoc . Document . GetUnits ( ) . GetFormatOptions ( UnitType . UT_Length ) . DisplayUnits . ToString ( ) . ToLower ( ) . Replace ( "dut_" , "" ) ;
104+ InjectScaleInKits ( GetScale ( units ) ) ; // this is used for feet to sane units conversion.
105105
106106 int i = 0 ;
107107 long currentBucketSize = 0 ;
108108 var errors = "" ;
109109 var failedSend = 0 ;
110110 var failedConvert = 0 ;
111- foreach ( var obj in objects )
111+ foreach ( var obj in objects )
112112 {
113- NotifyUi ( "update-client" , JsonConvert . SerializeObject ( new
113+ NotifyUi ( "update-client" , JsonConvert . SerializeObject ( new
114114 {
115- _id = ( string ) client . _id ,
115+ _id = ( string ) client . _id ,
116116 loading = true ,
117117 isLoadingIndeterminate = false ,
118118 loadingProgress = 1f * i ++ / objects . Count ( ) * 100 ,
119- loadingBlurb = string . Format ( "Converting and uploading objects: {0} / {1}" , i , objects . Count ( ) )
120- } ) ) ;
119+ loadingBlurb = string . Format ( "Converting and uploading objects: {0} / {1}" , i , objects . Count ( ) )
120+ } ) ) ;
121121
122122 try
123123 {
124- var revitElement = CurrentDoc . Document . GetElement ( ( string ) obj . Properties [ "revitUniqueId" ] ) ;
124+ var revitElement = CurrentDoc . Document . GetElement ( ( string ) obj . Properties [ "revitUniqueId" ] ) ;
125125
126- var conversionResult = SpeckleCore . Converter . Serialise ( new List < object > ( ) { revitElement } ) ;
127- var byteCount = Converter . getBytes ( conversionResult ) . Length ;
126+ var conversionResult = SpeckleCore . Converter . Serialise ( new List < object > ( ) { revitElement } ) ;
127+ var byteCount = Converter . getBytes ( conversionResult ) . Length ;
128128 currentBucketSize += byteCount ;
129129
130- if ( byteCount > 2e6 )
130+ if ( byteCount > 2e6 )
131131 {
132132 var problemId = revitElement . Id ;
133133 }
134134
135- convertedObjects . AddRange ( conversionResult ) ;
135+ convertedObjects . AddRange ( conversionResult ) ;
136136
137- if ( currentBucketSize > 5e5 || i >= objects . Count ( ) ) // aim for roughly 500kb uncompressed
137+ if ( currentBucketSize > 5e5 || i >= objects . Count ( ) ) // aim for roughly 500kb uncompressed
138138 {
139- LocalContext . PruneExistingObjects ( convertedObjects , apiClient . BaseUrl ) ;
139+ LocalContext . PruneExistingObjects ( convertedObjects , apiClient . BaseUrl ) ;
140140
141141 try
142142 {
143- var chunkResponse = apiClient . ObjectCreateAsync ( convertedObjects ) . Result . Resources ;
143+ var chunkResponse = apiClient . ObjectCreateAsync ( convertedObjects ) . Result . Resources ;
144144 int m = 0 ;
145- foreach ( var objConverted in convertedObjects )
145+ foreach ( var objConverted in convertedObjects )
146146 {
147- objConverted . _id = chunkResponse [ m ++ ] . _id ;
148- placeholders . Add ( new SpecklePlaceholder ( ) { _id = objConverted . _id } ) ;
149- if ( objConverted . Type != "Placeholder" ) LocalContext . AddSentObject ( objConverted , apiClient . BaseUrl ) ;
147+ objConverted . _id = chunkResponse [ m ++ ] . _id ;
148+ placeholders . Add ( new SpecklePlaceholder ( ) { _id = objConverted . _id } ) ;
149+ if ( objConverted . Type != "Placeholder" ) LocalContext . AddSentObject ( objConverted , apiClient . BaseUrl ) ;
150150 }
151151 }
152- catch ( Exception e )
152+ catch ( Exception e )
153153 {
154154 failedSend += convertedObjects . Count ;
155- NotifyUi ( "update-client" , JsonConvert . SerializeObject ( new
155+ NotifyUi ( "update-client" , JsonConvert . SerializeObject ( new
156156 {
157- _id = ( string ) client . _id ,
157+ _id = ( string ) client . _id ,
158158 errors = "Failed to send " + failedSend + " objects."
159- } ) ) ;
159+ } ) ) ;
160160 }
161161 currentBucketSize = 0 ;
162162 convertedObjects = new List < SpeckleObject > ( ) ; // reset the chunkness
163163 }
164164 }
165- catch ( Exception e )
165+ catch ( Exception e )
166166 {
167167 failedConvert ++ ;
168- NotifyUi ( "update-client" , JsonConvert . SerializeObject ( new
168+ NotifyUi ( "update-client" , JsonConvert . SerializeObject ( new
169169 {
170- _id = ( string ) client . _id ,
170+ _id = ( string ) client . _id ,
171171 errors = "Failed to convert " + failedConvert + " objects."
172- } ) ) ;
172+ } ) ) ;
173173 }
174174 }
175175
176- if ( failedConvert > 0 ) errors += String . Format ( "Failed to convert a total of {0} objects. " , failedConvert ) ;
177- if ( failedSend > 0 ) errors += String . Format ( "Failed to send a total of {0} objects. " , failedSend ) ;
176+ if ( failedConvert > 0 ) errors += String . Format ( "Failed to convert a total of {0} objects. " , failedConvert ) ;
177+ if ( failedSend > 0 ) errors += String . Format ( "Failed to send a total of {0} objects. " , failedSend ) ;
178178
179179 var myStream = new SpeckleStream ( ) { Objects = placeholders } ;
180180
181- var ug = UnitUtils . GetUnitGroup ( UnitType . UT_Length ) ;
181+ var ug = UnitUtils . GetUnitGroup ( UnitType . UT_Length ) ;
182182 var baseProps = new Dictionary < string , object > ( ) ;
183183
184- baseProps [ "units" ] = units ;
184+ baseProps [ "units" ] = units ;
185185
186- baseProps [ "unitsDictionary" ] = GetAndClearUnitDictionary ( ) ;
186+ baseProps [ "unitsDictionary" ] = GetAndClearUnitDictionary ( ) ;
187187
188188 myStream . BaseProperties = baseProps ;
189189 //myStream.BaseProperties = JsonConvert.SerializeObject(baseProps);
190190
191- NotifyUi ( "update-client" , JsonConvert . SerializeObject ( new
191+ NotifyUi ( "update-client" , JsonConvert . SerializeObject ( new
192192 {
193- _id = ( string ) client . _id ,
193+ _id = ( string ) client . _id ,
194194 loading = true ,
195195 isLoadingIndeterminate = true ,
196196 loadingBlurb = "Updating stream."
197- } ) ) ;
197+ } ) ) ;
198198
199- var response = apiClient . StreamUpdateAsync ( ( string ) client . streamId , myStream ) . Result ;
199+ var response = apiClient . StreamUpdateAsync ( ( string ) client . streamId , myStream ) . Result ;
200200
201201 var plural = objects . Count ( ) == 1 ? "" : "s" ;
202- NotifyUi ( "update-client" , JsonConvert . SerializeObject ( new
202+ NotifyUi ( "update-client" , JsonConvert . SerializeObject ( new
203203 {
204- _id = ( string ) client . _id ,
204+ _id = ( string ) client . _id ,
205205 loading = false ,
206206 loadingBlurb = "" ,
207207 message = $ "Done sending { objects . Count ( ) } object{ plural } .",
208208 errors
209- } ) ) ;
209+ } ) ) ;
210210
211- SpeckleTelemetry . RecordStreamUpdated ( "Revit" ) ;
211+ SpeckleTelemetry . RecordStreamUpdated ( "Revit" ) ;
212212 }
213213
214214 /// <summary>
215215 /// Pass selected element ids to UI
216216 /// </summary>
217217 /// <param name="args"></param>
218- public override void AddSelectionToSender ( string args )
218+ public override void AddSelectionToSender ( string args )
219219 {
220220 var doc = CurrentDoc . Document ;
221- var selectedObjects = CurrentDoc != null ? CurrentDoc . Selection . GetElementIds ( ) . Select ( id => doc . GetElement ( id ) . UniqueId ) . ToList ( ) : new List < string > ( ) ;
221+ var selectedObjects = CurrentDoc != null ? CurrentDoc . Selection . GetElementIds ( ) . Select ( id => doc . GetElement ( id ) . UniqueId ) . ToList ( ) : new List < string > ( ) ;
222222
223223 NotifyUi ( "update-selection" , JsonConvert . SerializeObject ( new
224224 {
225225 selectedObjects
226226 } ) ) ;
227227 }
228228
229- public override void RemoveSelectionFromSender ( string args )
229+ public override void RemoveSelectionFromSender ( string args )
230230 {
231231 // NOT IMPLEMENTED
232232
@@ -310,7 +310,7 @@ private IEnumerable<SpeckleObject> GetSelectionFilterObjects(ISelectionFilter fi
310310 selectionIds = new FilteredElementCollector ( doc )
311311 . WhereElementIsNotElementType ( )
312312 . WherePasses ( categoryFilter )
313- . Select ( x=> x . UniqueId ) . ToList ( ) ;
313+ . Select ( x => x . UniqueId ) . ToList ( ) ;
314314
315315 }
316316 else if ( filter . Name == "Parameter" )
@@ -320,22 +320,23 @@ private IEnumerable<SpeckleObject> GetSelectionFilterObjects(ISelectionFilter fi
320320 var propFilter = filter as PropertySelectionFilter ;
321321 var query = new FilteredElementCollector ( doc )
322322 . WhereElementIsNotElementType ( )
323+ . WhereElementIsViewIndependent ( )
324+ . OfClass ( typeof ( FamilyInstance ) )
323325 . Where ( fi => fi . LookupParameter ( propFilter . PropertyName ) != null ) ;
324326
325-
326-
327+ propFilter . PropertyValue = propFilter . PropertyValue . ToLowerInvariant ( ) ;
327328
328329 switch ( propFilter . PropertyOperator )
329330 {
330331 case "equals" :
331- query = query . Where ( fi => fi . LookupParameter ( propFilter . PropertyName ) . AsValueString ( ) == propFilter . PropertyValue ) ;
332+ query = query . Where ( fi => GetStringValue ( fi . LookupParameter ( propFilter . PropertyName ) ) == propFilter . PropertyValue ) ;
332333 break ;
333334 case "contains" :
334- query = query . Where ( fi => fi . LookupParameter ( propFilter . PropertyName ) . AsValueString ( ) . Contains ( propFilter . PropertyValue ) ) ;
335+ query = query . Where ( fi => GetStringValue ( fi . LookupParameter ( propFilter . PropertyName ) ) . Contains ( propFilter . PropertyValue ) ) ;
335336 break ;
336337 case "is greater than" :
337338 query = query . Where ( fi => UnitUtils . ConvertFromInternalUnits (
338- fi . LookupParameter ( propFilter . PropertyName ) . AsDouble ( ) ,
339+ fi . LookupParameter ( propFilter . PropertyName ) . AsDouble ( ) ,
339340 fi . LookupParameter ( propFilter . PropertyName ) . DisplayUnitType ) > double . Parse ( propFilter . PropertyValue ) ) ;
340341 break ;
341342 case "is less than" :
@@ -350,7 +351,10 @@ private IEnumerable<SpeckleObject> GetSelectionFilterObjects(ISelectionFilter fi
350351 selectionIds = query . Select ( x => x . UniqueId ) . ToList ( ) ;
351352
352353 }
353- catch { }
354+ catch ( Exception e )
355+ {
356+ Console . WriteLine ( e ) ;
357+ }
354358 }
355359
356360 // LOCAL STATE management
@@ -395,6 +399,19 @@ private IEnumerable<SpeckleObject> GetSelectionFilterObjects(ISelectionFilter fi
395399
396400 return objects ;
397401 }
402+
403+ private string GetStringValue ( Parameter p )
404+ {
405+ string value = "" ;
406+ if ( ! p . HasValue )
407+ return value ;
408+ if ( string . IsNullOrEmpty ( p . AsValueString ( ) ) && string . IsNullOrEmpty ( p . AsString ( ) ) )
409+ return value ;
410+ if ( ! string . IsNullOrEmpty ( p . AsValueString ( ) ) )
411+ return p . AsValueString ( ) . ToLowerInvariant ( ) ;
412+ else
413+ return p . AsString ( ) . ToLowerInvariant ( ) ;
414+ }
398415 #endregion
399416
400417 }
0 commit comments