public bool MoveNext() { if (m_IsStart) { m_IsStart = false; m_CurDispDim = m_Feat.GetFirstDisplayDimension() as IDisplayDimension; } else { m_CurDispDim = m_Feat.GetNextDisplayDimension(m_CurDispDim) as IDisplayDimension; } if (m_CurDispDim != null) { //NOTE: parent feature, such as extrude will also return all dimensions from child features, such as sketch var featName = m_CurDispDim.GetDimension2(0).FullName.Split('@')[1]; if (!string.Equals(featName, m_Feat.Name, StringComparison.CurrentCultureIgnoreCase)) { return(MoveNext()); } } return(m_CurDispDim != null); }
private void SetAndReleaseDimension(IDisplayDimension dispDim, int index, double val, string confName) { var dim = dispDim.GetDimension2(0); dim.SetSystemValue3(val, (int)swSetValueInConfiguration_e.swSetValue_InSpecificConfigurations, new string[] { confName }); ReleaseDimension(dispDim, dim); }
internal SwDimension(IDisplayDimension dispDim, ISwDocument doc, ISwApplication app) : base(dispDim, doc, app) { if (doc == null) { throw new ArgumentNullException(nameof(doc)); } DisplayDimension = dispDim; m_ValueChangedHandler = new SwDimensionChangeEventsHandler(this, doc); }
internal SwDimension(IModelDoc2 model, IDisplayDimension dispDim) : base(null, dispDim) { if (model == null) { throw new ArgumentNullException(nameof(model)); } DisplayDimension = dispDim; m_ValueChangedHandler = new SwDimensionChangeEventsHandler(this, model); }
public static double getMateValue(Component2 component) { Feature mate = swAssembly.FeatureByName(component.Name2 + "-distance"); if (mate == null) { return(-1); } IDisplayDimension dispDim = (IDisplayDimension)mate.GetFirstDisplayDimension(); IDimension dim = dispDim.IGetDimension(); double[] someRet = dim.GetSystemValue3((int)swSetValueInConfiguration_e.swSetValue_InSpecificConfigurations, new string[] { component.ReferencedConfiguration }); return(someRet[0]); }
public void CopyLink() { Clipboard.Clear(); AddinDocument addinDoc = _swAddin.GetActiveDoc(); if (addinDoc == null) { return; } string swDoc = addinDoc.FullFileName; ModelDoc2 swModelDoc = SWHelper.GetDocByFileName(swDoc); // нужно учитывать что браться на редактирование может документ не открытый в PLM. тогда здесь будет null и нужно либо открывать документ, либо работать через DMDocument if (swModelDoc == null) { return; } SelectionMgr mSelectionMgr = swModelDoc.ISelectionManager; String sz = ""; var tp = mSelectionMgr.GetSelectedObjectType3(1, -1); if (tp == (int)swSelectType_e.swSelDIMENSIONS) { IDisplayDimension sel = (IDisplayDimension)mSelectionMgr.GetSelectedObject6(1, 0); sz = sel.GetDimension2(0).FullName; Clipboard.SetText(sz); } /* if (tp == (int)swSelectType_e.swSelNOTES) * { * INote sel = (INote)mSelectionMgr.GetSelectedObject6(1, 0); mSelectionMgr.IGetSelectedObjectsComponent2 * sel * * Annotation swAnn = (Annotation)sel.GetAnnotation(); * swAnn. * ModelDocExtension mde = (ModelDocExtension)swModel.Extension; * int id = mde.GetObjectId(swAnn); * * swFeature.GetNameForSelection(out sz); * }*/ //if (sz.Length != 0) MessageBox.Show(sz); }
private static void ReleaseDimension(IDisplayDimension dispDim, Dimension dim = null) { //NOTE: releasing the pointers as unreleased pointer might cause crash if (dim != null && Marshal.IsComObject(dim)) { Marshal.ReleaseComObject(dim); dim = null; } if (dispDim != null && Marshal.IsComObject(dispDim)) { Marshal.ReleaseComObject(dispDim); dispDim = null; } GC.Collect(); GC.Collect(); GC.WaitForPendingFinalizers(); }
public void Dispose() { Dispose(true); //NOTE: releasing the pointers as unreleased pointer might cause crash if (m_Dimension != null && Marshal.IsComObject(m_Dimension)) { Marshal.ReleaseComObject(m_Dimension); m_Dimension = null; } if (DisplayDimension != null && Marshal.IsComObject(DisplayDimension)) { Marshal.ReleaseComObject(DisplayDimension); DisplayDimension = null; } GC.Collect(); GC.Collect(); GC.WaitForPendingFinalizers(); }
public void updateExtrusionDepth(double depthInInches) { if (depthInInches < 0) { return; } double depthInMeters = Utilities.inchesToMeters(depthInInches); IDisplayDimension dispDim = (IDisplayDimension)extrusion.GetFirstDisplayDimension(); IDimension dim = dispDim.IGetDimension(); dim.SetSystemValue3(depthInMeters, (int)swSetValueInConfiguration_e.swSetValue_InSpecificConfigurations, new string[] { belongsTo.ReferencedConfiguration }); swFeatureMgr.EditRollback((int)swMoveRollbackBarTo_e.swMoveRollbackBarToEnd, extrusion.Name); swAssembly.EditRebuild(); swDoc.EditRebuild3(); swDoc.ForceRebuild3(false); swAssembly.EditAssembly(); }
internal DimensionData(IDisplayDimension dispDim, string name) { DisplayDimension = dispDim; Dimension = dispDim.GetDimension2(0); Name = name; }
internal SwDimension(IDisplayDimension dispDim) : base(null, dispDim) { DisplayDimension = dispDim; }
private void OnDimensionChange(DocumentHandler docHandler, IDisplayDimension dispDim) { App.SendMsgToUser2($"'{docHandler.Model.GetTitle()}' dimension change: {dispDim.IGetDimension().FullName} = {dispDim.IGetDimension().Value}", (int)swMessageBoxIcon_e.swMbInformation, (int)swMessageBoxBtn_e.swMbOk); }
internal void SetParameters(IModelDoc2 model, IFeature feat, IMacroFeatureData featData, object parameters, out MacroFeatureOutdateState_e state) { string[] paramNames; int[] paramTypes; string[] paramValues; object[] selection; int[] dimTypes; double[] dimValues; IBody2[] bodies; Parse(parameters, out paramNames, out paramTypes, out paramValues, out selection, out dimTypes, out dimValues, out bodies); if (selection != null && selection.Any()) { var dispWraps = selection.Select(s => new DispatchWrapper(s)).ToArray(); featData.SetSelections2(dispWraps, new int[selection.Length], new IView[selection.Length]); } featData.EditBodies = bodies; var dispDimsObj = featData.GetDisplayDimensions() as object[]; IDisplayDimension[] dispDims = null; if (dispDimsObj != null) { dispDims = new IDisplayDimension[dispDimsObj.Length]; for (int i = 0; i < dispDimsObj.Length; i++) { dispDims[i] = dispDimsObj[i] as IDisplayDimension; dispDimsObj[i] = null; } } var dimsVersion = GetDimensionsVersion(featData); ConvertParameters(parameters.GetType(), dimsVersion, conv => { dispDims = conv.ConvertDisplayDimensions(model, feat, dispDims); }); if (dispDims != null) { try { if (dispDims.Length != dimValues.Length) { throw new ParametersMismatchException("Dimensions mismatch"); } for (int i = 0; i < dispDims.Length; i++) { var dispDim = dispDims[i]; if (!(dispDim is DisplayDimensionPlaceholder)) { SetAndReleaseDimension(dispDim, i, dimValues[i], featData.CurrentConfiguration.Name); } } } catch { ReleaseDisplayDimensions(dispDims); throw; } } state = GetState(featData, dispDims); if (paramNames.Any()) { //macro feature dimensions cannot be changed in the existing feature //reverting the dimensions version if (state.HasFlag(MacroFeatureOutdateState_e.Dimensions)) { var index = Array.IndexOf(paramNames, VERSION_DIMENSIONS_NAME); paramValues[index] = dimsVersion.ToString(); } featData.SetParameters(paramNames, paramTypes, paramValues); UpdateParameters(featData, paramNames, paramTypes, paramValues); } }
public static void moveToPosition(Component2 component, int position, double originalPosition) { /* * Buttons have 1 and 0 positions * Sliders move along the track from 1 to 0 in 4 steps * Dials move in a circle from 0 to 2*pi in 4 steps */ // for now, we will just try to move around the buttons, sliders, and dials, because that is least impossible! if (position == -1) { return; } // see discussions at // https://forum.solidworks.com/message/341157#341157#341157 double newDistance = 0; if (component.Name2.StartsWith("button")) { if (position == 1) { newDistance = Utilities.inchesToMeters(.02); } else { newDistance = originalPosition; } } else if (component.Name2.StartsWith("slider")) { newDistance = position / 4.0 * originalPosition; } else if (component.Name2.StartsWith("dial")) { newDistance = position * Math.PI / 2; } if (position == 0) { newDistance = originalPosition; } Feature mate = swAssembly.FeatureByName(component.Name2 + "-distance"); if (mate == null) { return; } IDisplayDimension dispDim = (IDisplayDimension)mate.GetFirstDisplayDimension(); IDimension dim = dispDim.IGetDimension(); dim.SetSystemValue3(newDistance, (int)swSetValueInConfiguration_e.swSetValue_InSpecificConfigurations, new string[] { component.ReferencedConfiguration }); swAssembly.EditRebuild(); swDoc.ForceRebuild3(false); swAssembly.EditAssembly(); }
internal object GetParameters(IFeature feat, IMacroFeatureData featData, IModelDoc2 model, Type paramsType, out IDisplayDimension[] dispDims, out string[] dispDimParams, out IBody2[] editBodies, out MacroFeatureOutdateState_e state) { object retParamNames = null; object retParamValues = null; object paramTypes = null; object retSelObj; object selObjType; object selMarks; object selDrViews; object compXforms; featData.GetParameters(out retParamNames, out paramTypes, out retParamValues); featData.GetSelections3(out retSelObj, out selObjType, out selMarks, out selDrViews, out compXforms); IDisplayDimension[] localDispDims = null; var dispDimParamsMap = new SortedDictionary <int, string>(); try { var dispDimsObj = featData.GetDisplayDimensions() as object[]; if (dispDimsObj != null) { localDispDims = new IDisplayDimension[dispDimsObj.Length]; for (int i = 0; i < localDispDims.Length; i++) { localDispDims[i] = dispDimsObj[i] as IDisplayDimension; dispDimsObj[i] = null; } } else { localDispDims = null; } object[] editBodiesObj = featData.EditBodies as object[]; IBody2[] localEditBodies = null; if (editBodiesObj != null) { localEditBodies = editBodiesObj.Cast <IBody2>().ToArray(); } var paramNames = retParamNames as string[]; var paramValues = retParamValues as string[]; var selObjects = retSelObj as object[]; var parameters = new Dictionary <string, string>(); var paramsVersion = new Version(); var dimsVersion = new Version(); if (paramNames != null && paramValues != null) { for (int i = 0; i < paramNames.Length; i++) { if (paramNames[i] == VERSION_PARAMETERS_NAME) { paramsVersion = new Version(paramValues[i]); } else if (paramNames[i] == VERSION_DIMENSIONS_NAME) { paramsVersion = new Version(paramValues[i]); } else { parameters.Add(paramNames[i], paramValues[i]); } } } ConvertParameters(paramsType, paramsVersion, conv => { parameters = conv.ConvertParameters(model, feat, parameters); localEditBodies = conv.ConvertEditBodies(model, feat, localEditBodies); selObjects = conv.ConvertSelections(model, feat, selObjects); localDispDims = conv.ConvertDisplayDimensions(model, feat, localDispDims); }); var resParams = Activator.CreateInstance(paramsType); TraverseParametersDefinition(resParams.GetType(), (prp) => { AssignObjectsToProperty(resParams, selObjects, prp, parameters); }, (dimType, prp) => { var dimIndices = GetObjectIndices(prp, parameters); if (dimIndices.Length != 1) { throw new InvalidOperationException( "It could only be one index associated with dimension"); } var dimInd = dimIndices.First(); if (localDispDims.Length > dimInd) { var dispDim = localDispDims[dimInd]; if (!(dispDim is DisplayDimensionPlaceholder)) { var dim = dispDim.GetDimension2(0); var val = (dim.GetSystemValue3( (int)swInConfigurationOpts_e.swSpecifyConfiguration, new string[] { featData.CurrentConfiguration.Name }) as double[])[0]; prp.SetValue(resParams, val, null); } dispDimParamsMap.Add(dimInd, prp.Name); } else { throw new IndexOutOfRangeException( $"Dimension at index {dimInd} id not present in the macro feature"); } }, (prp) => { AssignObjectsToProperty(resParams, localEditBodies, prp, parameters); }, prp => { var paramVal = GetParameterValue(parameters, prp.Name); var val = Convert.ChangeType(paramVal, prp.PropertyType); prp.SetValue(resParams, val, null); }); dispDims = localDispDims; editBodies = localEditBodies; state = GetState(featData, localDispDims); dispDimParams = dispDimParamsMap.Values.ToArray(); return(resParams); } catch { ReleaseDisplayDimensions(localDispDims); throw; } }
internal DimensionData(IDisplayDimension dispDim) { DisplayDimension = dispDim; Dimension = dispDim.GetDimension2(0); }
public IDisplayDimensionObject(IDisplayDimension IDisplayDimensioninstance) { IDisplayDimensionInstance = IDisplayDimensioninstance; }