getNestedPoints(BlockTableRecord Btr) { ObjectIdCollection ids = new ObjectIdCollection(); try { using (Transaction tr = BaseObjs.startTransactionDb()) { foreach (ObjectId idObj in Btr) { DBObject dbObj = tr.GetObject(idObj, OpenMode.ForRead); if (dbObj.GetType() == typeof(CogoPoint)) { ids.Add(dbObj.ObjectId); } } tr.Commit(); } } catch (System.Exception ex) { BaseObjs.writeDebug(string.Format("{0} Cogo.cs: line: 33", ex.Message)); } return(ids); }
idObjToTypeAndHandleStr(DBObject dbObj) { Debug.Assert(dbObj != null); string str1 = dbObj.GetType().Name; return(string.Format("< {0,-20} {1,4} >", str1, dbObj.Handle.ToString())); }
idObjToType(ObjectId objId) { string type = string.Empty; { // open up even if erased try { using (Transaction tr = BaseObjs.startTransactionDb()) { DBObject tmpObj = tr.GetObject(objId, OpenMode.ForRead, true); type = tmpObj.GetType().Name; tr.Commit(); } } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Db.cs: line: 351"); } } return(type); }
public override async Task <StreamState> SendStream(StreamState state) { var kit = KitManager.GetDefaultKit(); var converter = kit.LoadConverter(Utils.AutocadAppName); converter.SetContextDocument(Doc); var streamId = state.Stream.id; var client = state.Client; if (state.Filter != null) { state.SelectedObjectIds = GetObjectsFromFilter(state.Filter); } if (state.SelectedObjectIds.Count == 0) { RaiseNotification("Zero objects selected; send stopped. Please select some objects, or check that your filter can actually select something."); return(state); } var commitObj = new Base(); var units = Units.GetUnitsFromString(Doc.Database.Insunits.ToString()); commitObj["units"] = units; var conversionProgressDict = new ConcurrentDictionary <string, int>(); conversionProgressDict["Conversion"] = 0; Execute.PostToUIThread(() => state.Progress.Maximum = state.SelectedObjectIds.Count()); int convertedCount = 0; bool renamedlayers = false; foreach (var autocadObjectHandle in state.SelectedObjectIds) { if (state.CancellationTokenSource.Token.IsCancellationRequested) { return(null); } // get the db object from id AcadDb.Handle hn = new AcadDb.Handle(Convert.ToInt64(autocadObjectHandle, 16)); AcadDb.DBObject obj = hn.GetObject(out string type, out string layer); string cleanLayerName = Utils.RemoveInvalidDynamicPropChars(layer); if (!cleanLayerName.Equals(layer)) { renamedlayers = true; } if (obj == null) { state.Errors.Add(new Exception($"Failed to find local object ${autocadObjectHandle}.")); continue; } if (!converter.CanConvertToSpeckle(obj)) { state.Errors.Add(new Exception($"Objects of type ${type} are not supported")); continue; } // convert geo to speckle base if (!converter.CanConvertToSpeckle(obj)) { state.Errors.Add(new Exception($"Skipping object {autocadObjectHandle}, {obj.GetType()} type not supported")); continue; } Base converted = converter.ConvertToSpeckle(obj); if (converted == null) { state.Errors.Add(new Exception($"Failed to convert object ${autocadObjectHandle} of type ${type}.")); continue; } conversionProgressDict["Conversion"]++; UpdateProgress(conversionProgressDict, state.Progress); converted.applicationId = autocadObjectHandle; /* TODO: adding the extension dictionary / xdata per object * foreach (var key in obj.ExtensionDictionary) * { * converted[key] = obj.ExtensionDictionary.GetUserString(key); * } */ if (commitObj[$"@{cleanLayerName}"] == null) { commitObj[$"@{cleanLayerName}"] = new List <Base>(); } ((List <Base>)commitObj[$"@{cleanLayerName}"]).Add(converted); convertedCount++; } if (renamedlayers) { RaiseNotification("Replaced illegal chars ./ with - in one or more layer names."); } if (state.CancellationTokenSource.Token.IsCancellationRequested) { return(null); } Execute.PostToUIThread(() => state.Progress.Maximum = convertedCount); var transports = new List <ITransport>() { new ServerTransport(client.Account, streamId) }; var commitObjId = await Operations.Send( commitObj, state.CancellationTokenSource.Token, transports, onProgressAction : dict => UpdateProgress(dict, state.Progress), onErrorAction : (err, exception) => { Exceptions.Add(exception); } ); if (Exceptions.Count != 0) { RaiseNotification($"Failed to send: \n {Exceptions.Last().Message}"); return(null); } var actualCommit = new CommitCreateInput { streamId = streamId, objectId = commitObjId, branchName = state.Branch.name, message = state.CommitMessage != null ? state.CommitMessage : $"Pushed {convertedCount} elements from AutoCAD.", sourceApplication = Utils.AutocadAppName }; if (state.PreviousCommitId != null) { actualCommit.parents = new List <string>() { state.PreviousCommitId }; } try { var commitId = await client.CommitCreate(actualCommit); await state.RefreshStream(); state.PreviousCommitId = commitId; PersistAndUpdateStreamInFile(state); RaiseNotification($"{convertedCount} objects sent to {state.Stream.name}."); } catch (Exception e) { Globals.Notify($"Failed to create commit.\n{e.Message}"); state.Errors.Add(e); } return(state); }