public Inventor.Vector UpdateUnits(Inventor.Vector inp) { UnitsOfMeasure oUOM = _invApp.ActiveDocument.UnitsOfMeasure; inp.X = oUOM.ConvertUnits(inp.X, "cm", "m"); inp.Y = oUOM.ConvertUnits(inp.Y, "cm", "m"); inp.Z = oUOM.ConvertUnits(inp.Z, "cm", "m"); return(inp); }
public void ChangeView(double gyroY, double gyroX, double gyroZ, bool apply) { Inventor.Vector screenX = null; Inventor.Vector screenY = null; Inventor.Vector screenZ = null; screenZ = oCamera.Target.VectorTo(oCamera.Eye); screenZ.Normalize(); screenY = oCamera.UpVector.AsVector(); screenX = screenY.CrossProduct(screenZ); Inventor.Matrix rotX = oTG.CreateMatrix(); rotX.SetToRotation(gyroX, screenX, oCamera.Target); Inventor.Matrix rotY = oTG.CreateMatrix(); rotY.SetToRotation(gyroY, screenY, oCamera.Target); Inventor.Matrix rotZ = oTG.CreateMatrix(); rotZ.SetToRotation(gyroZ, screenZ, oCamera.Target); Inventor.Matrix rot = oTG.CreateMatrix(); rot = rotX; rot.PostMultiplyBy(rotY); rot.PostMultiplyBy(rotZ); Inventor.Point newEye = oCamera.Eye; newEye.TransformBy(rot); Inventor.UnitVector newUp = oCamera.UpVector; newUp.TransformBy(rot); oCamera.Eye = newEye; oCamera.UpVector = newUp; if (apply) { oCamera.Apply(); } else { oCamera.ApplyWithoutTransition(); } }
public void TranslateView(double scaleX, double scaleY) { Inventor.Vector X = null; Inventor.Vector Y = null; Inventor.Vector Z = null; Z = oCamera.Target.VectorTo(oCamera.Eye); Z.Normalize(); Y = oCamera.UpVector.AsVector(); X = Y.CrossProduct(Z); X.ScaleBy(scaleX); Y.ScaleBy(scaleY); Inventor.Point newEye = oCamera.Eye; newEye.TranslateBy(X); newEye.TranslateBy(Y); Inventor.Point newTarget = oCamera.Target; newTarget.TranslateBy(X); newTarget.TranslateBy(Y); oCamera.Eye = newEye; oCamera.Target = newTarget; oCamera.ApplyWithoutTransition(); }
public void insertFootFeature(Face selectFace, string indexnumber)//用于插入具有安装面的元件 { string oInputName; PartDocument oPartDocument; oPartDocument = (PartDocument)m_inventorApplication.ActiveDocument; PartComponentDefinition oPartCompDef; oPartCompDef = oPartDocument.ComponentDefinition; Face oSelectFace; oSelectFace = selectFace; PartFeatures oFeatures; oFeatures = oPartCompDef.Features; iFeatureDefinition oiFeatureDef; oiFeatureDef = oFeatures.iFeatures.CreateiFeatureDefinition(filepath + "\\" + indexnumber + "Footprint.ide"); ucsNumber = JudgeFaceUcs(oSelectFace); Inventor.Vector oVector = oPartCompDef.UserCoordinateSystems[ucsNumber].XAxis.Line.Direction.AsVector(); foreach (iFeatureInput oInput in oiFeatureDef.iFeatureInputs) { if (oInput.Name == "放置平面" || oInput.Name == "x轴" || oInput.Name == "y轴" || oInput.Name == "y" || oInput.Name == "x") { switch (oInput.Name) { case "放置平面": iFeatureSketchPlaneInput oPlaneInput; oPlaneInput = (iFeatureSketchPlaneInput)oInput; oPlaneInput.PlaneInput = oSelectFace; oPlaneInput.SetPosition(m_Point, oVector, rotateAngle); break; case "x轴": iFeatureEntityInput oInputXAxis; oInputXAxis = (iFeatureEntityInput)oInput; oInputXAxis.Entity = oPartCompDef.UserCoordinateSystems[ucsNumber].XAxis; break; case "y轴": iFeatureEntityInput oInputYAxis; oInputYAxis = (iFeatureEntityInput)oInput; oInputYAxis.Entity = oPartCompDef.UserCoordinateSystems[ucsNumber].YAxis; break; case "y": iFeatureParameterInput oInputx; oInputx = (iFeatureParameterInput)oInput; oInputx.Value = Yposition; break; case "x": iFeatureParameterInput oInputy; oInputy = (iFeatureParameterInput)oInput; oInputy.Value = Xposition; break; } } else { oInputName = oInput.Name; iFeatureParameterInput oParameXInput; oParameXInput = (iFeatureParameterInput)oInput; oParameXInput.Expression = m_connectToaccess.SelectConnectToAccess(oInputName); } } iFeature oiFeature; oiFeature = oFeatures.iFeatures.Add(oiFeatureDef); m_iFeature = oiFeature; double disminX = GetValueFromExpression(m_connectToaccess.SelectConnectToAccess("LminX")) / 2.0 + Xposition; double disminY = GetValueFromExpression(m_connectToaccess.SelectConnectToAccess("LminY")) / 2.0 + Yposition; double dismaxX = GetValueFromExpression(m_connectToaccess.SelectConnectToAccess("LmaxX")) / 2.0 + Xposition; double dismaxY = GetValueFromExpression(m_connectToaccess.SelectConnectToAccess("LmaxY")) / 2.0 + Yposition; DrawSketch(selectFace, Yposition, Xposition, disminY, disminX, dismaxY, dismaxX, m_iFeatureName); //------------------------------------------------------------------------------编写保存iFeature名称的属性集 RotateSketch(oPartCompDef, m_iFeatureName, Yposition, Xposition, rotateAngle); WriteAttribute(oiFeature, m_Point, "Yes", rotateAngle); oiFeature.Name = m_iFeatureName; //------------------------------------------------------------------------------拉伸曲面以区分网络 string sql = @"select * from ComponentsDb where ComponentsDb.IndexName='" + indexname + "'"; string cavityType = m_connectToaccess.GetSingleInformation(sql, "CavityType"); if (cavityType == "二通插装孔") { ColorAllCavPort(oiFeature, oSelectFace); } ColorAllFootpPort(oiFeature, oSelectFace); ShowPortColor(); oPartDocument.Update2(); }
private void insertFootFeature(Face selectFace)//用于插入具有安装面的元件 { string oInputName; PartDocument oPartDocument; oPartDocument = (PartDocument)m_inventorApplication.ActiveDocument; PartComponentDefinition oPartCompDef; oPartCompDef = oPartDocument.ComponentDefinition; Face oSelectFace; oSelectFace = selectFace; PartFeatures oFeatures; oFeatures = oPartCompDef.Features; iFeatureDefinition oiFeatureDef; oiFeatureDef = oFeatures.iFeatures.CreateiFeatureDefinition(m_filepath + "\\" + m_codenumber + "Footprint.ide"); int ucsNumber = JudgeFaceUcs(oSelectFace); Inventor.Vector oVector = oPartCompDef.UserCoordinateSystems[ucsNumber].XAxis.Line.Direction.AsVector(); foreach (iFeatureInput oInput in oiFeatureDef.iFeatureInputs) { if (oInput.Name == "放置平面" || oInput.Name == "x轴" || oInput.Name == "y轴" || oInput.Name == "x" || oInput.Name == "y") { switch (oInput.Name) { case "放置平面": iFeatureSketchPlaneInput oPlaneInput; oPlaneInput = (iFeatureSketchPlaneInput)oInput; oPlaneInput.PlaneInput = oSelectFace; oPlaneInput.SetPosition(m_Point, oVector, m_InsertAngle); break; case "x轴": iFeatureEntityInput oInputXAxis; oInputXAxis = (iFeatureEntityInput)oInput; oInputXAxis.Entity = oPartCompDef.UserCoordinateSystems[ucsNumber].XAxis; break; case "y轴": iFeatureEntityInput oInputYAxis; oInputYAxis = (iFeatureEntityInput)oInput; oInputYAxis.Entity = oPartCompDef.UserCoordinateSystems[ucsNumber].YAxis; break; case "y": iFeatureParameterInput oInputx; oInputx = (iFeatureParameterInput)oInput; oInputx.Value = Yposition; break; case "x": iFeatureParameterInput oInputy; oInputy = (iFeatureParameterInput)oInput; oInputy.Value = Xposition; break; } } else { oInputName = oInput.Name; iFeatureParameterInput oParameXInput; oParameXInput = (iFeatureParameterInput)oInput; m_connectToaccess = new ConnectToAccess(m_filepath, m_filename, m_codename, m_indexname, m_codenumber); oParameXInput.Expression = m_connectToaccess.SelectConnectToAccess(oInputName); } } iFeature oiFeature; oiFeature = oFeatures.iFeatures.Add(oiFeatureDef); double disminX = GetValueFromExpression(m_connectToaccess.SelectConnectToAccess("LminX")) / 2 + Xposition; double disminY = GetValueFromExpression(m_connectToaccess.SelectConnectToAccess("LminY")) / 2 + Yposition; double dismaxX = GetValueFromExpression(m_connectToaccess.SelectConnectToAccess("LmaxX")) / 2 + Xposition; double dismaxY = GetValueFromExpression(m_connectToaccess.SelectConnectToAccess("LmaxY")) / 2 + Yposition; DrowSketch(selectFace, Yposition, Xposition, disminY, disminX, dismaxY, dismaxX, m_iFeatureName); RotateSketch(oPartCompDef, m_iFeatureName, Yposition, Xposition, m_InsertAngle); WriteAttribute(oiFeature, m_Point, "Yes", m_InsertAngle); //一定要在后面执行 oiFeature.Name = m_iFeatureName; }
private Vector3 InvToNumericsVec3(Vector upVector) { return(new Vector3((float)upVector.X, (float)upVector.Y, (float)upVector.Z)); }