Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Thank you very much, you are the best. After looking at the codes again and changing their order and structure, I got the result I wanted. I had been working on it for a long time and this really pissed me off. There was no correct result from the answers of those who returned from the forum.
After all, I am sharing my correct working codes here.

 

            string openIam = "C:\\Users\\username\\Documents\\Assembly1.iam";

            string fullpath1 = "C:\\Users\\username\\Desktop\\sampleIam\\partiam.iam";

            string fullpath2 = "C:\\Servers\\partiam.iam";

            var documentOpen = _application.Documents.Open(openIam, true);

  
            if (_application.ActiveDocument.DocumentType != DocumentTypeEnum.kAssemblyDocumentObject) return;

            documentOpen.UnitsOfMeasure.LengthUnits = UnitsTypeEnum.kMillimeterLengthUnits;

            AssemblyDocument StartDoc = _application.ActiveDocument as AssemblyDocument  ;

            var oSketch = _application.ActiveEditObject;

            var oAsmCompDef = StartDoc.ComponentDefinition;


            TransientGeometry transientGeometry = _application.TransientGeometry;



            Matrix matrix3 = transientGeometry.CreateMatrix();


            matrix3.SetTranslation(transientGeometry.CreateVector(0, 0, 0));

            ComponentOccurrence oOcc3;

            oOcc3 = oAsmCompDef.Occurrences.Add(fullpath1, matrix3);


            PlanarSketch osketch = oAsmCompDef.Sketches.Add(oAsmCompDef.WorkPlanes[3]);

            TransientGeometry transientgeo = _application.TransientGeometry;

            SketchEntitiesEnumerator objects = osketch.SketchLines.AddAsTwoPointRectangle(transientgeo.CreatePoint2d(20, 0), transientgeo.CreatePoint2d(95, 10));

            SketchLine sketchLine = objects[1] as SketchLine;

            double oneLine = sketchLine.Length;

            double copyLine = oneLine / 2;


            Profile oProfile = osketch.Profiles.AddForSolid();


            ExtrudeDefinition extrudeDefinition = oAsmCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kCutOperation);

            extrudeDefinition.SetDistanceExtent(42, PartFeatureExtentDirectionEnum.kSymmetricExtentDirection);

            var oExtrude = oAsmCompDef.Features.ExtrudeFeatures.Add(extrudeDefinition);


            int ipt1Xinput = Convert.ToInt16(ipt1xkonum.Text);

            int ipt2Xinput = int.Parse(ipt2xkonum.Text);

            int ipt1X = ipt1Xinput + 75;
            int ipt2X = ipt2Xinput + 75;

            Matrix matrix1 = transientGeometry.CreateMatrix();


            matrix1.SetTranslation(transientGeometry.CreateVector(ipt1X , 0, 0));



            string ipt1file = openFileDialog1.FileName;
            ComponentOccurrence oOcc1;
            oOcc1 = oAsmCompDef.Occurrences.Add(ipt1file , matrix1);

            Matrix matrix2 = transientGeometry.CreateMatrix();


            matrix1.SetTranslation(transientGeometry.CreateVector(ipt2X , 0, 0));

            string ipt2file = openFileDialog2.FileName;
            ComponentOccurrence oOcc2;
            oOcc2 = oAsmCompDef.Occurrences.Add(ipt2file , matrix2);


            

            StartDoc.SaveAs(fullpath2, false);