public static int Execute(/*params string[] parameters*/)
        {
            ComApi.InwOpState3 oState = ComApiBridge.ComApiBridge.State;

            Document doc = Application.ActiveDocument;

            ModelItemCollection currSelectionColl = doc.CurrentSelection.SelectedItems;

            if (currSelectionColl.Count > 0)
            {
                foreach (ModelItem item in currSelectionColl.DescendantsAndSelf)
                {
                    if (item.HasGeometry)
                    {
                        ComApi.InwOaPath oPath = ComApiBridge.ComApiBridge.ToInwOaPath(item);

                        Transform3D tr = item.Transform;//TODO: учитывать уже добавленную трансформацию!!!
                        //tr.Factor()
                        Transform3DComponents transform3DComponents = tr.Factor();
                        //transform3DComponents.ScaleOrientation
                        Point3D center = item.Geometry.BoundingBox.Center;

                        double z               = center.Z;
                        double zTransformed    = z * 1.1;
                        double correctionTrans = (z - zTransformed) /*/ 2*/;

                        ComApi.InwOpSelection comSelectionOut =
                            ComApiBridge.ComApiBridge.ToInwOpSelection(new ModelItemCollection()
                        {
                            item
                        });

                        ComApi.InwLTransform3f3 oTrans1
                            = (ComApi.InwLTransform3f3)oState
                              .ObjectFactory(ComApi.nwEObjectType.eObjectType_nwLTransform3f, null, null);
                        //растяжение по Z
                        ComApi.InwLVec3f scale
                            = (ComApi.InwLVec3f)oState
                              .ObjectFactory(ComApi.nwEObjectType.eObjectType_nwLVec3f, null, null);
                        scale.SetValue(1, 1, 1.1);
                        //смещение по Z
                        ComApi.InwLVec3f trans
                            = (ComApi.InwLVec3f)oState
                              .ObjectFactory(ComApi.nwEObjectType.eObjectType_nwLVec3f, null, null);
                        trans.SetValue(0, 0, correctionTrans);

                        //ComApi.InwLRotation3f scaleOrientation
                        //    = (ComApi.InwLRotation3f)oState
                        //    .ObjectFactory(ComApi.nwEObjectType.eObjectType_nwLRotation3f, null, null);
                        //ComApi.InwLUnitVec3f axis
                        //    = (ComApi.InwLUnitVec3f)oState
                        //    .ObjectFactory(ComApi.nwEObjectType.eObjectType_nwLUnitVec3f, null, null);
                        //axis.SetValue(0, 0, 1);
                        //scaleOrientation.SetValue(axis, 0);

                        //ComApi.InwLRotation3f Rotation
                        //    = (ComApi.InwLRotation3f)oState
                        //    .ObjectFactory(ComApi.nwEObjectType.eObjectType_nwLRotation3f, null, null);
                        //Rotation.SetValue(axis, 0);

                        //oTrans1.factor(scale, scaleOrientation, Rotation, trans);
                        //double[] matrix = ConvertDoubleArray((Array)((object)oTrans1.Matrix));

                        //oTrans1.MakeScale(scale);
                        //double[] matrix1 = ConvertDoubleArray((Array)((object)oTrans1.Matrix));
                        //oTrans1.MakeTranslation(trans);
                        //double[] matrix2 = ConvertDoubleArray((Array)((object)oTrans1.Matrix));

                        oTrans1.SetMatrix(new double[]
                        {
                            1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1.1, 0, 0, 0, correctionTrans, 1
                        });


                        //oTrans1.MakeScale(scaleVec);
                        oState.OverrideTransform(comSelectionOut, oTrans1);
                    }
                }
            }

            return(0);
        }
Exemple #2
0
        private void ClashByCOMAPI()
        {
            try
            {
                ComAPI.InwOpState10 oState;
                oState = COMBridge.State;

                //find the clash detective plugin
                ComAPI.InwOpClashElement m_clash = null;

                foreach (ComAPI.InwBase oPlugin in oState.Plugins())
                {
                    if (oPlugin.ObjectName == "nwOpClashElement")
                    {
                        m_clash = (ComAPI.InwOpClashElement)oPlugin;
                        break;
                    }
                }

                if (m_clash == null)
                {
                    System.Windows.Forms.MessageBox.Show(
                        "cannot find clash test plugin!");
                }


                System.Globalization.CultureInfo cultureInfo = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
                string format = "ddd MMM d HH:mm:ss zz00 yyyy";

                List <ClashTestCls> tests_array = new List <ClashTestCls>();


                foreach (ComAPI.InwOclClashTest test in m_clash.Tests())
                {
                    ClashTestCls oEachTest = new ClashTestCls();
                    oEachTest.DisplayName = test.name;

                    List <ClashResultCls> test_results_array = new List <ClashResultCls>();
                    foreach (ComAPI.InwOclTestResult issue in test.results())
                    {
                        ClashResultCls oEachResult = new ClashResultCls();
                        oEachResult.DisplayName = issue.name;
                        oEachResult.ApprovedBy  = issue.ApprovedBy;
                        oEachResult.Status      = issue.status.ToString();

                        //oEachResult.Found = issue.CreatedTime.ToUniversalTime().ToString();

                        ModelItem oMI1     = COMBridge.ToModelItem(issue.Path1);
                        string    path1_id = oMI1.PropertyCategories.FindPropertyByDisplayName("Entity Handle", "Value").Value.ToDisplayString();
                        oEachResult.path1ID = path1_id;
                        ModelItem oMI2     = COMBridge.ToModelItem(issue.Path2);
                        string    path2_id = oMI2.PropertyCategories.FindPropertyByDisplayName("Entity Handle", "Value").Value.ToDisplayString();
                        oEachResult.path2ID = path2_id;

                        oEachResult.viewpoint = new ClashResultVP();

                        ComAPI.InwNvViewPoint vp = issue.GetSuitableViewPoint();
                        oEachResult.viewpoint.Position = new double[3] {
                            vp.Camera.Position.data1,
                            vp.Camera.Position.data2,
                            vp.Camera.Position.data3
                        };

                        ComAPI.InwLVec3f oDirVec = vp.Camera.GetViewDir();
                        oEachResult.viewpoint.Target = new double[3] {
                            vp.Camera.Position.data1 + vp.FocalDistance * oDirVec.data1,
                            vp.Camera.Position.data2 + vp.FocalDistance * oDirVec.data2,
                            vp.Camera.Position.data3 + vp.FocalDistance * oDirVec.data3
                        };

                        ComAPI.InwLVec3f upVec = vp.Camera.GetUpVector();
                        oEachResult.viewpoint.UpVec = new double[3] {
                            upVec.data1, upVec.data2, upVec.data3
                        };

                        ComAPI.InwLRotation3f rot = vp.Camera.Rotation;
                        oEachResult.viewpoint.RotAxis = new double[3] {
                            rot.GetAxis().data1, rot.GetAxis().data2, rot.GetAxis().data3
                        };
                        oEachResult.viewpoint.RotAngle = rot.angle;

                        test_results_array.Add(oEachResult);
                    }

                    oEachTest.ClashResults = test_results_array.ToArray();
                    tests_array.Add(oEachTest);
                }     //Test

                string jsonStr = JsonConvert.SerializeObject(tests_array.ToArray());

                const String strClient   = "http://localhost:3001";
                RestClient   _thisclient = new RestClient(strClient);

                RestRequest authReq = new RestRequest();
                authReq.Resource = "ClashTestRoute/postNewClash";
                authReq.Method   = Method.POST;

                byte[] fileData = System.Text.Encoding.Default.GetBytes(jsonStr);
                authReq.AddParameter("Content-Length", fileData.Length);
                authReq.AddHeader("Content-Type", "application/octet-stream");
                authReq.AddFile("file", fileData, "clashtestresult.json", "application/octet-stream");
                IRestResponse result = _thisclient.Execute(authReq);
                if (result.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    System.Windows.Forms.MessageBox.Show("The updated clash json has been sent to server successfully!");
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("failed to upload clash json to server! " + result.StatusCode.ToString());
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString());
            }
        }