/// <summary> /// Serialize all selected objects and marks to the the macro feature data /// </summary> private void SaveSelections() { var t = ModelDoc.GetMacroFeatureDataSelectionInfo(Database); SwFeatureData.SetSelections2(ComWangling.ObjectArrayToDispatchWrapper(t.Item1), t.Item2, t.Item3); Debug.Assert(SwFeatureData.GetSelectionCount() == t.Item1.Length); }
protected override object Regenerate(IModeler modeler) { SwFeatureData.EnableMultiBodyConsume = true; if (Database.Style == MulitWireBodiesData.StyleEnum.Wire) { var w = _R.NextDouble(); var line0 = modeler.CreateTrimmedLine(new Vector3(0, -w, 0), new Vector3(1, -w, 0)); var line1 = modeler.CreateTrimmedLine(new Vector3(0, w, 0), new Vector3(1, w, 0)); var wire0 = line0.CreateWireBody(); var wire1 = line1.CreateWireBody(); SwFeatureData.AddIdsToBody(wire0); SwFeatureData.AddIdsToBody(wire1); return(new[] { wire0, wire1 }); } else { var solid0 = modeler.CreateBox(new Vector3(0, 0, 0), Vector3.UnitX, 1, 1, 1); var solid1 = modeler.CreateBox(new Vector3(2, 0, 0), Vector3.UnitX, 1, 1, 1); SwFeatureData.AddIdsToBody(solid0); SwFeatureData.AddIdsToBody(solid0); return(new[] { solid0, solid1 }); } }
/// <summary> /// This should be called on all callbacks defined in ISwComFeature to /// initialize all the instance variables. /// </summary> /// <param name="app"></param> /// <param name="modelDoc"></param> /// <param name="feature"></param> private void Init(object app, object modelDoc, object feature) { if (app == null) { throw new ArgumentNullException(nameof(app)); } if (modelDoc == null) { throw new ArgumentNullException(nameof(modelDoc)); } // feature can be null SwApp = (ISldWorks)app; if (feature != null) { SwFeature = (IFeature)feature; SwFeatureData = (IMacroFeatureData)SwFeature.GetDefinition(); Database = SwFeatureData.Read <TData>(); } else { Database = new TData(); } ModelDoc = (IModelDoc2)modelDoc; }
/// <summary> /// Deserialize all selected objects and marks from the macro feature data. The selections /// will be active. Note you have to call Commit or Cancel after calling this or the feature /// manager tree will be in a rollback state. /// </summary> private void LoadSelections() { if (SwFeatureData == null) { return; } var result = SwFeatureData.AccessSelections(ModelDoc, null); if (!result) { throw new Exception("Can't access selections"); } }
protected override object Regenerate(IModeler modeler) { return(Database.Body .GetSingleObject <IBody2>(ModelDoc) .MatchUnsafe <object>(bodyFn => { var body = (IBody2)bodyFn().Copy(); SwFeatureData.EnableMultiBodyConsume = true; var splitBodies = SplitBodies(modeler, body, Database); if (splitBodies == null) { return "There was some error"; } foreach (var splitBody in splitBodies) { SwFeatureData.AddIdsToBody(splitBody); } return splitBodies; }, () => null)); }
/// <summary> /// Cancel editing of the macro feature. /// </summary> public void Cancel() { SwFeatureData?.ReleaseSelectionAccess(); }
/// <summary> /// Save all selection and parameters and modify the definition of the macro feature /// </summary> private void ModifyDefinition() { SaveSelections(); SwFeatureData.Write(Database); SwFeature.ModifyDefinition(SwFeatureData, ModelDoc, null); }