public CSimpleInteraction(Inventor.Application oApplication) { mApplication = oApplication; //Initialize events mInteractionEvents = mApplication.CommandManager.CreateInteractionEvents(); mSelectEvents = mInteractionEvents.SelectEvents; //Set event handler VB.Net Style mSelectEvents.OnSelect += new Inventor.SelectEventsSink_OnSelectEventHandler(this.mSelectEvents_OnSelect); mInteractionEvents.OnTerminate += new Inventor.InteractionEventsSink_OnTerminateEventHandler(this.mInteractionEvents_OnTerminate); //Clear filter and set new ones if needed mSelectEvents.ClearSelectionFilter(); //Always Disable mouse move if not needed for performances mSelectEvents.MouseMoveEnabled = false; mSelectEvents.Enabled = true; mSelectEvents.SingleSelectEnabled = true; //Remember to Start/Stop the interaction event mInteractionEvents.Start(); }
public void CreateExtrudeFeature(Inventor.Application ThisApplication) { PartDocument partDoc; partDoc = (PartDocument)ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, ThisApplication.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject, SystemOfMeasureEnum.kDefaultSystemOfMeasure, DraftingStandardEnum.kGB_DraftingStandard, null), true); PlanarSketch sketch; sketch = partDoc.ComponentDefinition.Sketches.Add(partDoc.ComponentDefinition.WorkPlanes[3], false); TransientGeometry transGeom; transGeom = ThisApplication.TransientGeometry; SketchPoints skPnts; skPnts = sketch.SketchPoints; skPnts.Add(transGeom.CreatePoint2d(0, 0), false); skPnts.Add(transGeom.CreatePoint2d(1, 0), false); skPnts.Add(transGeom.CreatePoint2d(1, 1), false); SketchLines lines; lines = sketch.SketchLines; System.Array Line = System.Array.CreateInstance(typeof(SketchLine), 3); SketchLine[] line = Line as SketchLine[]; line[0] = lines.AddByTwoPoints(skPnts[1], skPnts[2]); line[1] = lines.AddByTwoPoints(skPnts[2], skPnts[3]); line[2] = lines.AddByTwoPoints(skPnts[3], skPnts[1]); Profile profile; profile = sketch.Profiles.AddForSolid(true, null, null); ExtrudeFeature extFeature; extFeature = partDoc.ComponentDefinition.Features.ExtrudeFeatures.AddByDistanceExtent( profile,1.0, PartFeatureExtentDirectionEnum.kPositiveExtentDirection,PartFeatureOperationEnum.kJoinOperation,null); ThisApplication.ActiveView.Fit(true); }
public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime) { // This method is called by Inventor when it loads the addin. // The AddInSiteObject provides access to the Inventor Application object. // The FirstTime flag indicates if the addin is loaded for the first time. // Initialize AddIn members. m_inventorApplication = addInSiteObject.Application; // TODO: Add ApplicationAddInServer.Activate implementation. // e.g. event initialization, command creation etc. int largeIconSize = 0; if (m_inventorApplication.UserInterfaceManager.InterfaceStyle == InterfaceStyleEnum.kRibbonInterface) { largeIconSize = 32; } else { largeIconSize = 24; } ControlDefinitions controlDefs = m_inventorApplication.CommandManager.ControlDefinitions; stdole.IPictureDisp smallPicture1 = AxHostConverter.ImageToPictureDisp(new Icon(@"Resources\Icon1.ico").ToBitmap()); stdole.IPictureDisp largePicture1 = AxHostConverter.ImageToPictureDisp(new Icon(@"Resources\Icon1.ico").ToBitmap()); m_TreeViewBrowser = controlDefs.AddButtonDefinition("HierarchyPane", "BrowserSample:HierarchyPane", CommandTypesEnum.kNonShapeEditCmdType, m_ClientId,null ,null , smallPicture1, largePicture1); m_TreeViewBrowser.OnExecute+= new ButtonDefinitionSink_OnExecuteEventHandler(m_TreeViewBrowser_OnExecute); stdole.IPictureDisp smallPicture2 = AxHostConverter.ImageToPictureDisp(new Icon(@"Resources\Icon2.ico").ToBitmap()); stdole.IPictureDisp largePicture2 = AxHostConverter.ImageToPictureDisp(new Icon(@"Resources\Icon2.ico").ToBitmap()); m_ActiveXBrowser = controlDefs.AddButtonDefinition("ActiveXPane", "BrowserSample:ActiveXPane", CommandTypesEnum.kNonShapeEditCmdType, m_ClientId, null ,null , smallPicture2, largePicture2); m_ActiveXBrowser.OnExecute += new ButtonDefinitionSink_OnExecuteEventHandler(m_ActiveXBrowser_OnExecute); stdole.IPictureDisp smallPicture3 = AxHostConverter.ImageToPictureDisp(new Icon(@"Resources\Icon3.ico").ToBitmap()); stdole.IPictureDisp largePicture3 = AxHostConverter.ImageToPictureDisp(new Icon(@"Resources\Icon3.ico").ToBitmap()); m_DoBrowserEvents = controlDefs.AddButtonDefinition("DoBrowserEvents", "BrowserSample:DoBrowserEvents", CommandTypesEnum.kNonShapeEditCmdType, m_ClientId,null ,null , smallPicture3, largePicture3); m_DoBrowserEvents.OnExecute += new ButtonDefinitionSink_OnExecuteEventHandler(m_DoBrowserEvents_OnExecute); // Get the assembly ribbon. Inventor.Ribbon partRibbon = m_inventorApplication.UserInterfaceManager.Ribbons["Part"]; // Get the "Part" tab. Inventor.RibbonTab partTab = partRibbon.RibbonTabs[1]; Inventor.RibbonPanel partPanel = partTab.RibbonPanels[1]; partPanel.CommandControls.AddButton(m_TreeViewBrowser, true); partPanel.CommandControls.AddButton(m_DoBrowserEvents); partPanel.CommandControls.AddButton(m_ActiveXBrowser); }
public Form1(Inventor.Application oApp) { // This call is required by the Windows Form Designer. InitializeComponent(); // Add any initialization after the InitializeComponent() call. _macros = new Macros(oApp); MemberInfo[] methods = _macros.GetType().GetMembers(); foreach (MemberInfo member in methods) { if (member.DeclaringType.Name == "Macros" && member.MemberType == MemberTypes.Method) { ComboBoxMacros.Items.Add(member.Name); } } if (ComboBoxMacros.Items.Count > 0) { ComboBoxMacros.SelectedIndex = 0; Button1.Enabled = true; } }
public void ContextNarrowing() { Inventor context = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian"); ConditionValidator cv1 = new ConditionValidator("DOB.Year == 1856", null); ConditionValidator cv2 = new ConditionValidator("Year == 1856", null); StaticListableObjectFactory factory = new StaticListableObjectFactory(); factory.AddObject("cv1", cv1); factory.AddObject("cv2", cv2); ValidatorReference v1 = new ValidatorReference(); v1.ObjectFactory = factory; v1.Name = "cv1"; IValidationErrors errors = new ValidationErrors(); Assert.IsTrue(v1.Validate(context, null, errors)); Assert.IsTrue(v1.Validate(context, errors)); ValidatorReference v2 = new ValidatorReference(); v2.ObjectFactory = factory; v2.Name = "cv2"; v2.Context = Expression.Parse("DOB"); Assert.IsTrue(v2.Validate(context, null, errors)); Assert.IsTrue(v2.Validate(context, errors)); ValidatorReference v3 = new ValidatorReference("false"); v3.ObjectFactory = factory; v3.Name = "cv2"; v3.Context = Expression.Parse("DOB"); Assert.IsTrue(v3.Validate(null, errors)); }
public void ChangeBalloons(Inventor.Application ThisApplication) { DrawingDocument drawDoc; drawDoc = (DrawingDocument)ThisApplication.ActiveDocument; Sheet sheet; sheet = drawDoc.ActiveSheet; long balloonCount; balloonCount = 1; foreach(Balloon balloon in sheet.Balloons) { balloon.SetBalloonType(BalloonTypeEnum.kHexagonBalloonType, null); balloon.PlacementDirection = BalloonDirectionEnum.kBottomDirection; long valueSetCount; valueSetCount = 1; foreach(BalloonValueSet balloonValueSet in balloon.BalloonValueSets) { balloonValueSet.OverrideValue = string.Format("Balloon {0} : ValueSet {1}", balloonCount, valueSetCount); valueSetCount = valueSetCount + 1; } balloonCount = balloonCount + 1; } }
public void ShowSurfaceArea(Inventor.Application ThisApplication) { //���õ������ĵ���ѡ������ SelectSet selectSet; selectSet = ThisApplication.ActiveDocument.SelectSet; //ȷ��ֻѡ����һ��ͼԪ if(selectSet.Count == 1) { //ȷ��ѡ����һ������ if (selectSet[1].GetType() is Face == false) { //���õ���ѡ��������� Face face; face = (Face)selectSet[1]; //��ʾ��ѡ�������� MessageBox.Show(string.Format("Surface area: {0} cm^2", face.Evaluator.Area)); } else { MessageBox.Show("You must select a single face."); } } else { MessageBox.Show("You must select a single face."); } }
public void CreateRevolveFeature(Inventor.Application ThisApplication) { PartDocument partDoc; partDoc = (PartDocument)ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, ThisApplication.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject, SystemOfMeasureEnum.kDefaultSystemOfMeasure, DraftingStandardEnum.kGB_DraftingStandard, null), true); PlanarSketch sketch; sketch = partDoc.ComponentDefinition.Sketches.Add(partDoc.ComponentDefinition.WorkPlanes[3], false); TransientGeometry transGeom; transGeom = ThisApplication.TransientGeometry; SketchPoints skPnts; skPnts = sketch.SketchPoints; skPnts.Add(transGeom.CreatePoint2d(0, 0), false); skPnts.Add(transGeom.CreatePoint2d(1, 0), false); skPnts.Add(transGeom.CreatePoint2d(1, 1), false); SketchLines lines; lines = sketch.SketchLines; SketchLine line; line = lines.AddByTwoPoints(skPnts[1], skPnts[2]); SketchCircles circs; circs = sketch.SketchCircles; SketchCircle circ; circ = circs.AddByCenterRadius(skPnts[3], 0.5); Profile profile; profile = sketch.Profiles.AddForSolid(true, null, null); RevolveFeature revFeature; revFeature = partDoc.ComponentDefinition.Features.RevolveFeatures.AddFull(profile, line, PartFeatureOperationEnum.kJoinOperation); ThisApplication.ActiveView.Fit(true); }
public void CreateDrawing(Inventor.Application ThisApplication) { DrawingDocument drawingDoc; drawingDoc = (DrawingDocument)ThisApplication.ActiveDocument; Sheet sheet; sheet = drawingDoc.Sheets[1]; Point2d point1; point1 = ThisApplication.TransientGeometry.CreatePoint2d(5, 5); _Document partDoc; partDoc = ThisApplication.Documents.Open("c:\\testpart.ipt", false); DrawingView view1; view1 = sheet.DrawingViews.AddBaseView(partDoc, point1, 1, ViewOrientationTypeEnum.kBottomViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle, "", null, null); partDoc.Close(true); Point2d point2; point2 = ThisApplication.TransientGeometry.CreatePoint2d(15, 40); DrawingSketch drawingSketch; drawingSketch = sheet.Sketches.Add(); drawingSketch.Edit(); SketchLine sketchLine; sketchLine = drawingSketch.SketchLines.AddByTwoPoints(point1, point2); drawingSketch.ExitEdit(); SectionDrawingView view2; view2 = sheet.DrawingViews.AddSectionView(view1, drawingSketch, point2, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle, 1, true, "", false, true, null); drawingSketch.Visible = false; }
public void WithoutTypeConversion() { Hashtable source = new Hashtable(); Inventor target = new Inventor(); source["name"] = "Nikola Tesla"; source["dob"] = new DateTime(1856, 7, 9); // I know this is pupin's graduation year but I need a date here source["dateofgraduation"] = new DateTime(1883,1,1); source["inventions"] = new string[] {"One", "Two"}; mgr.BindSourceToTarget(source, target, null); Assert.IsTrue(mgr.HasBindings); Assert.AreEqual("Nikola Tesla", target.Name); Assert.AreEqual(new DateTime(1856, 7, 9), target.DOB); Assert.AreEqual(new string[] {"One", "Two"}, target.Inventions); Assert.IsNull(target.PlaceOfBirth.City); Assert.IsNull(target.PlaceOfBirth.Country); target.Name = "Tesla, Nikola"; target.DOB = DateTime.Today; target.PlaceOfBirth.City = "Smiljan"; target.PlaceOfBirth.Country = "Lika"; mgr.BindTargetToSource(source, target, null); Assert.AreEqual("Tesla, Nikola", source["name"]); Assert.AreEqual(DateTime.Today, source["dob"]); Assert.AreEqual("One", ((string[]) source["inventions"])[0]); Assert.AreEqual("Smiljan", source["cityOfBirth"]); Assert.AreEqual("Lika", source["countryOfBirth"]); }
public QubeItToolsChangeProcessor(Inventor.Application inventorApplication, IChangeProcessorParent parentClass, string internalName, string commandName, string clientID) { _inventorApplication = inventorApplication; _parentClass = parentClass; _clientID = clientID; _changeDefInternalName = internalName; _changeDefCommandName = commandName; }
public Form1(Inventor.Application oApplication) { // This call is required by the Windows Form Designer. InitializeComponent(); // Add any initialization after the InitializeComponent() call. mApplication = oApplication; }
public void CreateSketchWithCons(Inventor.Application ThisApplication) { PartDocument partDoc; partDoc = (PartDocument)ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, ThisApplication.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject, SystemOfMeasureEnum.kDefaultSystemOfMeasure, DraftingStandardEnum.kGB_DraftingStandard, null),true); PlanarSketch sketch; sketch = partDoc.ComponentDefinition.Sketches.Add(partDoc.ComponentDefinition.WorkPlanes[3], false); TransientGeometry transGeom; transGeom = ThisApplication.TransientGeometry; SketchPoints skPnts; skPnts = sketch.SketchPoints; skPnts.Add(transGeom.CreatePoint2d(0, 0), false); skPnts.Add(transGeom.CreatePoint2d(1.0, 0), false); skPnts.Add(transGeom.CreatePoint2d(1.0, 0.5), false); skPnts.Add(transGeom.CreatePoint2d(2.2, 0.5), false); skPnts.Add(transGeom.CreatePoint2d(0.5, 1.5), false); skPnts.Add(transGeom.CreatePoint2d(0, 1.0), false); skPnts.Add(transGeom.CreatePoint2d(2.7, 1.5), false); skPnts.Add(transGeom.CreatePoint2d(0.5, 1.0), false); SketchLines lines; lines = sketch.SketchLines; System.Array Line = System.Array.CreateInstance(typeof(SketchLine), 6); SketchLine[] line = Line as SketchLine[]; line[0] = lines.AddByTwoPoints(skPnts[1], skPnts[2]); line[1] = lines.AddByTwoPoints(skPnts[2], skPnts[3]); line[2] = lines.AddByTwoPoints(skPnts[3], skPnts[4]); line[3] = lines.AddByTwoPoints(skPnts[4], skPnts[7]); line[4] = lines.AddByTwoPoints(skPnts[7], skPnts[5]); line[5] = lines.AddByTwoPoints(skPnts[6], skPnts[1]); SketchArcs arcs; arcs = sketch.SketchArcs; SketchArc arc; arc = arcs.AddByCenterStartEndPoint(skPnts[8], skPnts[5], skPnts[6], true); sketch.GeometricConstraints.AddPerpendicular((SketchEntity)line[3], (SketchEntity)line[4], true, true); ThisApplication.ActiveView.Update(); sketch.GeometricConstraints.AddTangent((SketchEntity)line[4], (SketchEntity)arc, null); sketch.GeometricConstraints.AddTangent((SketchEntity)line[5], (SketchEntity)arc, null); ThisApplication.ActiveView.Update(); sketch.GeometricConstraints.AddParallel((SketchEntity)line[2], (SketchEntity)line[4], true, true); ThisApplication.ActiveView.Update(); sketch.GeometricConstraints.AddHorizontal((SketchEntity)line[4], true); ThisApplication.ActiveView.Update(); }
public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime) { m_inventorApplication = addInSiteObject.Application; m_ApplicationEvents = m_inventorApplication.ApplicationEvents; m_ApplicationEvents.OnOpenDocument += this.m_ApplicationEvents_OnOpenDocument; mControlForm = new Form1(m_inventorApplication); mControlForm.ShowModeless(); }
public void DrawASketchRectangle(Inventor.Application InvApp) { PartDocument oPartDoc = InvApp.ActiveDocument as PartDocument; PartComponentDefinition oPartDef = oPartDoc.ComponentDefinition; Point2d oPoint1 = InvApp.TransientGeometry.CreatePoint2d(0, 0); Point2d oPoint2 = InvApp.TransientGeometry.CreatePoint2d(10, 10); oPartDef.Sketches[1].SketchLines.AddAsTwoPointRectangle(oPoint1, oPoint2); InvApp.ActiveDocument.Views[1].Fit(); }
public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime) { // This method is called by Inventor when it loads the addin. // The AddInSiteObject provides access to the Inventor Application object. // The FirstTime flag indicates if the addin is loaded for the first time. // Initialize AddIn members. m_inventorApplication = addInSiteObject.Application; // TODO: Add ApplicationAddInServer.Activate implementation. // e.g. event initialization, command creation etc. System.Windows.Forms.MessageBox.Show("I am loaded!!", "Hello World AddIn"); }
public void WhenInvalid() { Inventor context = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian"); IValidationErrors errors = new ValidationErrors(); ErrorMessageAction action = new ErrorMessageAction("{0}, {1}", "errors"); action.Parameters = new IExpression[] {Expression.Parse("Name"), Expression.Parse("Nationality")}; action.Execute(false, context, null, errors); Assert.IsFalse(errors.IsEmpty); Assert.AreEqual(1, errors.GetErrors("errors").Count); Assert.AreEqual(context.Name + ", " + context.Nationality, errors.GetResolvedErrors("errors", new NullMessageSource())[0]); }
public void FalseScalarExpression() { Inventor tesla = new Inventor(); tesla.Name = "Soltan Gris"; ConditionValidator validator = new ConditionValidator(Expression.Parse("Name == 'Nikola Tesla'"), null); validator.Actions = new ErrorMessageAction[] {new ErrorMessageAction("Wrong name", "InventorValidator") }; IValidationErrors errors = new ValidationErrors(); Assert.IsFalse(validator.Validate(tesla, errors)); Assert.IsFalse(errors.IsEmpty); IList<string> namedErrors = errors.GetResolvedErrors("InventorValidator", new NullMessageSource()); Assert.AreEqual(1, namedErrors.Count); string error = (string) namedErrors[0]; Assert.AreEqual("Wrong name", error); }
public Form1(Inventor.Application oApp) { InitializeComponent(); // Add any initialization after the InitializeComponent() call. mAngleBox = new DigitTextBox(); mAngleBox.Name = "AngleBox"; mAngleBox.Location = new System.Drawing.Point(80, 197); mAngleBox.Size = new System.Drawing.Size(48, 30); mAngleBox.TabIndex = 3; mAngleBox.Text = ""; this.Controls.Add(mAngleBox); mApp = oApp; }
public VertMidPointRectangle(IInventorButton rectangleButton, Inventor.Application inventorApplication = null) { _inventorApplication = inventorApplication; _rectangleButton = rectangleButton; _changeProcessor = new General.QubeItToolsChangeProcessor(_inventorApplication, this, "VertMidPtRect", "Vertical Mid-Point Rectangle", StandardAddInServer.AddInServerId); TransientGeometry tG = _inventorApplication.TransientGeometry; _upperRightPoint2d = tG.CreatePoint2d(); _upperLeftPoint2d = tG.CreatePoint2d(); _lowerLeftPoint2d = tG.CreatePoint2d(); _lowerRightPoint2d = tG.CreatePoint2d(); _constructionLineButton = _inventorApplication.CommandManager.ControlDefinitions["SketchConstructionCmd"] as ButtonDefinition; _centerLineButton = _inventorApplication.CommandManager.ControlDefinitions["SketchCenterlineCmd"] as ButtonDefinition; _sketchOnlyButton = _inventorApplication.CommandManager.ControlDefinitions["SketchOnlyCmd"] as ButtonDefinition; }
public void WhenInvalid() { Inventor context = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian"); Dictionary <string, object> vars = new Dictionary <string, object>(); ExpressionAction action = new ExpressionAction("#result = 'valid'", "#result = 'invalid'"); action.Execute(false, context, vars, null); Assert.AreEqual("invalid", vars["result"]); action = new ExpressionAction(Expression.Parse("#result = Name"), Expression.Parse("#result = Nationality")); action.Execute(false, context, vars, null); Assert.AreEqual(context.Nationality, vars["result"]); action = new ExpressionAction(); action.Valid = Expression.Parse("#result = DOB.Year"); action.Invalid = Expression.Parse("#result = DOB.Month"); action.Execute(false, context, vars, null); Assert.AreEqual(context.DOB.Month, vars["result"]); vars.Clear(); action = new ExpressionAction("#result = 'valid'", null); action.Execute(false, context, vars, null); Assert.IsFalse(vars.ContainsKey("result"), "Result should not exist when invalid expression is null."); }
public void WithTypeConversion() { Hashtable source = new Hashtable(); Inventor target = new Inventor(); source["name"] = "Nikola Tesla"; source["dob"] = "1856-7-9"; source["inventions"] = "One,Two"; // I know this is pupin's graduation year but I need a date here source["dateofgraduation"] = "1883-1-1"; mgr.BindSourceToTarget(source, target, null); Assert.IsTrue(mgr.HasBindings); Assert.AreEqual("Nikola Tesla", target.Name); Assert.AreEqual(new DateTime(1856, 7, 9), target.DOB); Assert.AreEqual(new string[] { "One", "Two" }, target.Inventions); Assert.IsNull(target.PlaceOfBirth.City); Assert.IsNull(target.PlaceOfBirth.Country); target.Name = "Tesla, Nikola"; target.DOB = DateTime.Today; target.PlaceOfBirth.City = "Smiljan"; target.PlaceOfBirth.Country = "Lika"; mgr.BindTargetToSource(source, target, null); Assert.AreEqual("Tesla, Nikola", source["name"]); Assert.AreEqual(DateTime.Today, source["dob"]); Assert.AreEqual("One", ((string[])source["inventions"])[0]); Assert.AreEqual("Smiljan", source["cityOfBirth"]); Assert.AreEqual("Lika", source["countryOfBirth"]); }
public void UnhandledTypeConversionExceptionTargetToSource() { BaseBindingManager dbm = new BaseBindingManager(); Inventor st = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian"); st.Inventions = new string[] { "Invention One", "Invention Two" }; dbm.AddBinding("pob", "DOB"); try { dbm.BindTargetToSource(st, st, null); Assert.Fail("Binding date to custom Place type should throw an exception."); } catch (TypeMismatchException) {} // binding state is not remembered with ValidationErrors=null! try { dbm.BindSourceToTarget(st, st, null); Assert.Fail("Binding custom Place to date type should throw an exception."); } catch (TypeMismatchException) {} }
public void WhenValid() { Inventor context = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian"); IDictionary vars = new Hashtable(); ExpressionAction action = new ExpressionAction("#result = 'valid'", "#result = 'invalid'"); action.Execute(true, context, vars, null); Assert.AreEqual("valid", vars["result"]); action = new ExpressionAction(Expression.Parse("#result = Name"), Expression.Parse("#result = Nationality")); action.Execute(true, context, vars, null); Assert.AreEqual(context.Name, vars["result"]); action = new ExpressionAction(); action.Valid = Expression.Parse("#result = DOB.Year"); action.Invalid = Expression.Parse("#result = DOB.Month"); action.Execute(true, context, vars, null); Assert.AreEqual(context.DOB.Year, vars["result"]); vars.Clear(); action = new ExpressionAction(null, "#result = 'invalid'"); action.Execute(true, context, vars, null); Assert.IsFalse(vars.Contains("result"), "Result should not exist when valid expression is null."); }
public void TestCaching() { ICache cache = new NonExpiringCache(); context.ObjectFactory.RegisterSingleton("inventors", cache); ProxyFactory pf = new ProxyFactory(new InventorStore()); pf.AddAdvisors(cacheAspect); IInventorStore store = (IInventorStore)pf.GetProxy(); Assert.AreEqual(0, cache.Count); IList inventors = store.GetAll(); Assert.AreEqual(2, cache.Count); store.Delete((Inventor)inventors[0]); Assert.AreEqual(1, cache.Count); Inventor tesla = store.Load("Nikola Tesla"); Assert.AreEqual(2, cache.Count); store.Save(tesla); Assert.AreEqual(2, cache.Count); Assert.AreEqual("Serbian", ((Inventor)cache.Get("Nikola Tesla")).Nationality); store.DeleteAll(); Assert.AreEqual(0, cache.Count); }
////// protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (keyData == (Keys.A))//west { West.PerformClick(); } if (keyData == (Keys.W))//north { North.PerformClick(); } if (keyData == (Keys.D))//east { East.PerformClick(); } if (keyData == (Keys.S))//south { South.PerformClick(); } if (keyData == (Keys.R)) //rest { Restandsleep.PerformClick(); } if (keyData == (Keys.Q)) { Attack.PerformClick(); } if (keyData == (Keys.I)) { Inventor.PerformClick(); } return(base.ProcessCmdKey(ref msg, keyData)); }
public void DefaultResolvesUsingCurrentUICulture() { Inventor tesla = CreateInventor(null); Assert.AreEqual("Nikola Tesla", tesla.Name); Assert.AreEqual("Srbin", tesla.Nationality); }
public InventorStore() { Inventor tesla = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), null); Inventor pupin = new Inventor("Mihajlo Pupin", new DateTime(1854, 10, 9), null); inventors.Add("Nikola Tesla", tesla); inventors.Add("Mihajlo Pupin", pupin); }
public void WhenValid() { Inventor context = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian"); IValidationErrors errors = new ValidationErrors(); ErrorMessageAction action = new ErrorMessageAction("error", "errors"); action.Execute(true, context, null, errors); Assert.IsTrue(errors.IsEmpty); }
public void TestSerbianLatin() { Inventor tesla = CreateInventor(new CultureInfo(CultureInfoUtils.SerbianLatinCultureName)); Assert.AreEqual("Nikola Tesla", tesla.Name); Assert.AreEqual("Srbin", tesla.Nationality); Assert.AreEqual(new DateTime(1856, 7, 9), tesla.DOB); Assert.AreEqual("Hrvatska", tesla.PlaceOfBirth.Country); Assert.AreEqual("Smiljan", tesla.PlaceOfBirth.City); }
public void TestInvariantCulture() { Inventor tesla = CreateInventor(CultureInfo.InvariantCulture); Assert.AreEqual("Nikola Tesla", tesla.Name); Assert.AreEqual("Serbian", tesla.Nationality); Assert.AreEqual(new DateTime(1856, 7, 9), tesla.DOB); Assert.AreEqual("Croatia", tesla.PlaceOfBirth.Country); Assert.AreEqual("Smiljan", tesla.PlaceOfBirth.City); }
public void TestSerbianCyrillic() { Inventor tesla = CreateInventor(new CultureInfo(CultureInfoUtils.SerbianCyrillicCultureName)); Assert.AreEqual("Никола Тесла", tesla.Name); Assert.AreEqual("Србин", tesla.Nationality); Assert.AreEqual(new DateTime(1856, 7, 9), tesla.DOB); Assert.AreEqual("Хрватска", tesla.PlaceOfBirth.Country); Assert.AreEqual("Смиљан", tesla.PlaceOfBirth.City); }
public void TrueScalarExpression() { Inventor tesla = new Inventor(); tesla.Name = "Nikola Tesla"; ConditionValidator validator = new ConditionValidator(Expression.Parse("Name == 'Nikola Tesla'"), null); Assert.IsTrue(validator.Validate(tesla, new ValidationErrors())); }
public void Inventor_Delegate_Succeeds() { var inventor = new Inventor(new ExpensesStrategy(), new ImprovementStrategy(), new RentStrategy()); inventor.MakeSound(); Assert.NotNull(inventor.CalculateExpenses(DateTime.MinValue, DateTime.MaxValue)); Assert.NotNull(inventor.RentCost(DateTime.MinValue, DateTime.MaxValue)); Assert.NotNull(inventor.ImprovementCost(inventor.Quality)); }
public void Inventor_Delegate_Fails() { var inventor = new Inventor(); inventor.MakeSound(); Assert.Null(inventor.CalculateExpenses(DateTime.MinValue, DateTime.MaxValue)); Assert.Null(inventor.RentCost(DateTime.MinValue, DateTime.MaxValue)); Assert.Null(inventor.ImprovementCost(inventor.Quality)); }
public void WhenActionIsNotExecutedBecauseWhenExpressionReturnsFalse() { Inventor context = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian"); Dictionary <string, object> vars = new Dictionary <string, object>(); ExpressionAction action = new ExpressionAction("#result = 'valid'", "#result = 'invalid'"); action.When = Expression.Parse("false"); action.Execute(true, context, vars, null); Assert.IsFalse(vars.ContainsKey("result")); }
public void WhenActionIsNotExecutedBecauseWhenExpressionReturnsFalse() { Inventor context = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian"); IValidationErrors errors = new ValidationErrors(); ErrorMessageAction action = new ErrorMessageAction("{0}, {1}", "errors"); action.When = Expression.Parse("false"); action.Execute(false, context, null, errors); Assert.IsTrue(errors.IsEmpty); }
public void Employee_Delegate_Succeeds() { var hall = new Hall(); var inventor = new Inventor(); var employee = new Employee(new ExpensesStrategy(), new RentStrategy()); employee.Clean(hall); employee.Fix(inventor); Assert.NotNull(employee.CalculateExpenses(DateTime.MinValue, DateTime.MaxValue)); Assert.NotNull(employee.RentCost(DateTime.MinValue, DateTime.MaxValue)); }
private void mSelectEvents_OnSelect(Inventor.ObjectsEnumerator JustSelectedEntities, Inventor.SelectionDeviceEnum SelectionDevice, Inventor.Point ModelPosition, Inventor.Point2d ViewPosition, Inventor.View View) { if (JustSelectedEntities.Count != 0) { object selectedObj = JustSelectedEntities[1]; System.Windows.Forms.MessageBox.Show((string) ("Selected Entity: " + Information.TypeName(selectedObj)), "Simple Interaction"); } }
public void Employee_Delegate_Fails() { var hall = new Hall(); var inventor = new Inventor(); var employee = new Employee(); employee.Clean(hall); employee.Fix(inventor); Assert.Null(employee.CalculateExpenses(DateTime.MinValue, DateTime.MaxValue)); Assert.Null(employee.RentCost(DateTime.MinValue, DateTime.MaxValue)); }
public void TestConstructors() { IDynamicConstructor newInventor = DynamicConstructor.Create( typeof(Inventor).GetConstructor(new Type[] { typeof(string), typeof(DateTime), typeof(string) })); Inventor ana = (Inventor)newInventor.Invoke(new object[] { "Ana Maria Seovic", new DateTime(2004, 8, 14), "Serbian" }); Assert.AreEqual("Ana Maria Seovic", ana.Name); IDynamicConstructor newDate = DynamicConstructor.Create( typeof(DateTime).GetConstructor(new Type[] { typeof(int), typeof(int), typeof(int) })); Assert.AreEqual(DateTime.Today, newDate.Invoke(new object[] { DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day })); }
public static void EntitiesInventorTest() { var inv = new Inventor { InventorId = 0, FullName = "text", Adress = "Ref", Email = "em", Password = "******" }; Assert.Equal(0, inv.GetPersonId()); }
public void TestVariables() { var tesla = new Inventor("Nikola Tesla", "Serbian"); var context = new StandardEvaluationContext(); context.SetVariable("newName", "Mike Tesla"); context.SetRootObject(tesla); parser.ParseExpression("Foo = #newName").GetValue(context); Assert.Equal("Mike Tesla", tesla.Foo); }
private static void SetupRootContextObject(StandardEvaluationContext testContext) { var c = new GregorianCalendar(); var tesla = new Inventor("Nikola Tesla", c.ToDateTime(1856, 7, 9, 0, 0, 0, GregorianCalendar.CurrentEra), "Serbian"); tesla.PlaceOfBirth = new PlaceOfBirth("SmilJan"); tesla.Inventions = new string[] { "Telephone repeater", "Rotating magnetic field principle", "Polyphase alternating-current system", "Induction motor", "Alternating-current power transmission", "Tesla coil transformer", "Wireless communication", "Radio", "Fluorescent lights" }; testContext.SetRootObject(tesla); }
public void TestValidArgument() { MethodInfo method = typeof(ValidationTarget).GetMethod("Save"); Inventor inventor = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian"); ValidationTarget target = new ValidationTarget(); object[] args = new object[] { inventor }; ExpectValidatorRetrieval("required", requiredValidator); advice.Before(method, args, target); method.Invoke(target, args); Assert.AreEqual("NIKOLA TESLA", inventor.Name); }
static SpelDocumentationTests() { Tesla = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian"); Tesla.PlaceOfBirth = new PlaceOfBirth("SmilJan"); Tesla.Inventions = new string[] { "Telephone repeater", "Rotating magnetic field principle", "Polyphase alternating-current system", "Induction motor", "Alternating-current power transmission", "Tesla coil transformer", "Wireless communication", "Radio", "Fluorescent lights" }; Pupin = new Inventor("Pupin", new DateTime(1856, 7, 9), "Idvor"); Pupin.PlaceOfBirth = new PlaceOfBirth("Idvor"); }
public void WhenInvalid() { Inventor context = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian"); IValidationErrors errors = new ValidationErrors(); ErrorMessageAction action = new ErrorMessageAction("{0}, {1}", "errors"); action.Parameters = new IExpression[] { Expression.Parse("Name"), Expression.Parse("Nationality") }; action.Execute(false, context, null, errors); Assert.IsFalse(errors.IsEmpty); Assert.AreEqual(1, errors.GetErrors("errors").Count); Assert.AreEqual(context.Name + ", " + context.Nationality, errors.GetResolvedErrors("errors", new NullMessageSource())[0]); }
public void DirectionTargetToSource() { BaseBindingManager dbm = new BaseBindingManager(); Inventor source = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian"); Hashtable target = new Hashtable(); dbm.AddBinding("Name", "['name']", BindingDirection.TargetToSource); dbm.BindSourceToTarget(source, target, null); Assert.IsNull(target["name"]); target["name"] = "Mihajlo Pupin"; dbm.BindTargetToSource(source, target, null); Assert.AreEqual("Mihajlo Pupin", source.Name); }
public void WhenInvalidThrowDefaultException() { Inventor context = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian"); IDictionary vars = new Hashtable(); ExceptionAction action = new ExceptionAction(); try { action.Execute(false, context, vars, null); Assert.Fail("Should have thrown exception"); } catch (ValidationException) { } }
public void WhenValid() { Inventor context = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian"); IDictionary vars = new Hashtable(); ExceptionAction action = new ExceptionAction(); try { action.Execute(true, context, vars, null); } catch (Exception) { Assert.Fail("Should not have thrown exception"); } }
public void WhenInvalidThrowDefaultException() { Inventor context = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian"); Dictionary<string, object> vars = new Dictionary<string, object>(); ExceptionAction action = new ExceptionAction(); try { action.Execute(false, context, vars, null); Assert.Fail("Should have thrown exception"); } catch (ValidationException) { } }
public void WhenInvalidThrowCustomException() { Inventor context = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian"); Dictionary<string, object> vars = new Dictionary<string, object>(); ExceptionAction action = new ExceptionAction("new System.InvalidOperationException('invalid')"); try { action.Execute(false, context, vars, null); Assert.Fail("Should have thrown exception"); } catch (InvalidOperationException e) { Assert.AreEqual("invalid", e.Message); } }
private Inventor CreateInventor(CultureInfo culture) { Inventor inventor = new Inventor(); IMessageSource messageSource = CreateMessageSource(); if (culture == null) { localizer.ApplyResources(inventor, messageSource); } else { localizer.ApplyResources(inventor, messageSource, culture); } return(inventor); }
public Engine(string filePath,Inventor.PlanarSketch oSketch,Inventor.Application oApp, double slotHeight, double slotWidth) { _engine = Python.CreateEngine(new Dictionary<string, object>() { {"Frames", true}, {"FullFrames", true}}); _runtime = _engine.Runtime; Assembly invAssembly = Assembly.LoadFile(@"C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Autodesk.Inventor.Interop\v4.0_17.0.0.0__d84147f8b4276564\Autodesk.Inventor.interop.dll"); _runtime.LoadAssembly(invAssembly); _scope = _engine.CreateScope(); //Make variable names visible within the python file. These string names will be used an arguments in the python file. _scope.SetVariable("oPlanarSketch",oSketch); _scope.SetVariable("oApp",oApp); _scope.SetVariable("slotHeight",slotHeight); _scope.SetVariable("slotWidth",slotWidth); ScriptSource _script = _engine.CreateScriptSourceFromFile(filePath); _code = _script.Compile(); }
public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime) { _addInSiteObject = addInSiteObject; // This method is called by Inventor when it loads the addin. // The AddInSiteObject provides access to the Inventor Application object. // The FirstTime flag indicates if the addin is loaded for the first time. // Initialize AddIn members. _Application = addInSiteObject.Application; AdnInventorUtilities.Initialize(_Application, this.GetType()); ControlDefinitions ctrlDefs = _Application.CommandManager.ControlDefinitions; System.Drawing.Icon Icon32 = Resources.CGAUDemo_32x32; System.Drawing.Icon Icon16 = Resources.CGAUDemo_16x16; object IPictureDisp32 = PictureDispConverter.ToIPictureDisp(Icon32); object IPictureDisp16 = PictureDispConverter.ToIPictureDisp(Icon16); try { _MainControlButtonDef = ctrlDefs["Autodesk:AdskCGAUDemo:MainCtrl"] as ButtonDefinition; } catch { _MainControlButtonDef = ctrlDefs.AddButtonDefinition( " Demo \n Control ", "Autodesk:AdskCGAUDemo:MainCtrl", CommandTypesEnum.kEditMaskCmdType, AdnInventorUtilities.AddInGuid, "Client Graphics Demo AU", "Client Graphics Demo AU", IPictureDisp16, IPictureDisp32, ButtonDisplayEnum.kDisplayTextInLearningMode); } _MainControlButtonDef.OnExecute += new ButtonDefinitionSink_OnExecuteEventHandler(MainControlButtonDef_OnExecute); if (firstTime) { Ribbon partRibbon = _Application.UserInterfaceManager.Ribbons["Part"]; Ribbon asmRibbon = _Application.UserInterfaceManager.Ribbons["Assembly"]; Ribbon dwgRibbon = _Application.UserInterfaceManager.Ribbons["Drawing"]; AddToRibbon(partRibbon, AdnInventorUtilities.AddInGuid); AddToRibbon(asmRibbon, AdnInventorUtilities.AddInGuid); AddToRibbon(dwgRibbon, AdnInventorUtilities.AddInGuid); } }
public void CreateSketch(Inventor.Application ThisApplication) { if (ThisApplication.ActiveEditObject is Sketch == false) { MessageBox.Show("A sketch must be active."); } Sketch sketch; sketch = (Sketch)ThisApplication.ActiveEditObject; TransientGeometry transGeom; transGeom = ThisApplication.TransientGeometry; Point2d coord1; coord1 = transGeom.CreatePoint2d(0, 0); Point2d coord2; coord2 = transGeom.CreatePoint2d(5, 0); System.Array Line = System.Array.CreateInstance(typeof(SketchLine), 4); SketchLine[] lines = Line as SketchLine[]; lines[0] = sketch.SketchLines.AddByTwoPoints(coord1, coord2); coord1 = transGeom.CreatePoint2d(5, 3); lines[1] = sketch.SketchLines.AddByTwoPoints(lines[0].EndSketchPoint, coord1); coord1 = transGeom.CreatePoint2d(4, 3); coord2 = transGeom.CreatePoint2d(4, 4); SketchArc sketchArc; sketchArc = sketch.SketchArcs.AddByCenterStartEndPoint(coord1,lines[1].EndSketchPoint,coord2,true); coord1 = transGeom.CreatePoint2d(0, 4); lines[2] = sketch.SketchLines.AddByTwoPoints(sketchArc.EndSketchPoint,coord1); lines[3] = sketch.SketchLines.AddByTwoPoints(lines[0].StartSketchPoint, lines[2].EndSketchPoint); //���Լ�� sketch.GeometricConstraints.AddHorizontal((SketchEntity)lines[0], true); sketch.GeometricConstraints.AddPerpendicular((SketchEntity)lines[0], (SketchEntity)lines[1], false, true); sketch.GeometricConstraints.AddTangent((SketchEntity)lines[1], (SketchEntity)sketchArc, null); sketch.GeometricConstraints.AddTangent((SketchEntity)lines[2], (SketchEntity)sketchArc, null); sketch.GeometricConstraints.AddParallel((SketchEntity)lines[0], (SketchEntity)lines[2], true, false); sketch.GeometricConstraints.AddParallel((SketchEntity)lines[3], (SketchEntity)lines[1], true, false); //������ͼ PartDocument partDoc; partDoc = (PartDocument)ThisApplication.ActiveDocument; for (int i = 1; i <= partDoc.ComponentDefinition.Sketches.Count; i++ ) { MessageBox.Show(partDoc.ComponentDefinition.Sketches[i].Name); } //ͨ�����Ʒ��ʲ�ͼ Sketch sketch1; sketch1 = (Sketch)partDoc.ComponentDefinition.Sketches["��ͼ1"]; MessageBox.Show(sketch1.Name); }
public void WhenActionIsNotExecutedBecauseWhenExpressionReturnsFalse() { Inventor context = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian"); IDictionary vars = new Hashtable(); ExpressionAction action = new ExpressionAction("#result = 'valid'", "#result = 'invalid'"); action.When = Expression.Parse("false"); action.Execute(true, context, vars, null); Assert.IsFalse(vars.Contains("result")); }
///////////////////////////////////////////////////////////// // Constructor // ///////////////////////////////////////////////////////////// public AdnInteractionManager(Inventor.Application Application) { _Application = Application; _InteractionEvents = null; _SelectedEntities = new List<System.Object>(); _PreSelectFilters = new List<ObjectTypeEnum>(); }