static void Main(string[] args) { SolidEdgeFramework.Application application = null; SolidEdgeFramework.Documents documents = null; SolidEdgePart.SheetMetalDocument sheetMetalDocument = null; SolidEdgePart.RefPlanes refplanes = null; SolidEdgePart.RefPlane refplane = null; SolidEdgePart.Model model = null; SolidEdgePart.HoleDataCollection holeDataCollection = null; SolidEdgePart.ProfileSets profileSets = null; SolidEdgePart.ProfileSet profileSet = null; SolidEdgePart.Profiles profiles = null; SolidEdgePart.Profile profile = null; SolidEdgePart.Holes2d holes2d = null; SolidEdgePart.Hole2d hole2d = null; SolidEdgePart.Holes holes = null; SolidEdgePart.Hole hole = null; long profileStatus = 0; List <SolidEdgePart.Profile> profileList = new List <SolidEdgePart.Profile>(); SolidEdgePart.UserDefinedPatterns userDefinedPatterns = null; SolidEdgePart.UserDefinedPattern userDefinedPattern = null; SolidEdgeFramework.SelectSet selectSet = null; try { // Register with OLE to handle concurrency issues on the current thread. SolidEdgeCommunity.OleMessageFilter.Register(); // Connect to or start Solid Edge. application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true, true); // Get a reference to the Documents collection. documents = application.Documents; // Create a new sheetmetal document. sheetMetalDocument = documents.AddSheetMetalDocument(); // Always a good idea to give SE a chance to breathe. application.DoIdle(); // Call helper method to create the actual geometry. model = SheetMetalHelper.CreateBaseTabByCircle(sheetMetalDocument); // Get a reference to the RefPlanes collection. refplanes = sheetMetalDocument.RefPlanes; // Get a reference to front RefPlane. refplane = refplanes.GetFrontPlane(); // Get a reference to the ProfileSets collection. profileSets = sheetMetalDocument.ProfileSets; // Add new ProfileSet. profileSet = profileSets.Add(); // Get a reference to the Profiles collection. profiles = profileSet.Profiles; // Add new Profile. profile = profiles.Add(refplane); // Get a reference to the Holes2d collection. holes2d = profile.Holes2d; // This creates a cross pattern of holes. double[,] holeMatrix = new double[, ] { //{x, y} { 0.00, 0.00 }, { -0.01, 0.00 }, { -0.02, 0.00 }, { -0.03, 0.00 }, { -0.04, 0.00 }, { 0.01, 0.00 }, { 0.02, 0.00 }, { 0.03, 0.00 }, { 0.04, 0.00 }, { 0.00, -0.01 }, { 0.00, -0.02 }, { 0.00, -0.03 }, { 0.00, -0.04 }, { 0.00, 0.01 }, { 0.00, 0.02 }, { 0.00, 0.03 }, { 0.00, 0.04 } }; // Draw the Base Profile. for (int i = 0; i <= holeMatrix.GetUpperBound(0); i++) { // Add new Hole2d. hole2d = holes2d.Add( XCenter: holeMatrix[i, 0], YCenter: holeMatrix[i, 1]); } // Hide the profile. profile.Visible = false; // Close profile. profileStatus = profile.End(SolidEdgePart.ProfileValidationType.igProfileClosed); // Get a reference to the ProfileSet. profileSet = (SolidEdgePart.ProfileSet)profile.Parent; // Get a reference to the Profiles collection. profiles = profileSet.Profiles; // Add profiles to list for AddByProfiles(). for (int i = 1; i <= profiles.Count; i++) { profileList.Add(profiles.Item(i)); } // Get a reference to the HoleDataCollection collection. holeDataCollection = sheetMetalDocument.HoleDataCollection; // Add new HoleData. SolidEdgePart.HoleData holeData = holeDataCollection.Add( HoleType: SolidEdgePart.FeaturePropertyConstants.igRegularHole, HoleDiameter: 0.005, BottomAngle: 90); // Get a reference to the Holes collection. holes = model.Holes; // Add hole. hole = holes.AddFinite( Profile: profile, ProfilePlaneSide: SolidEdgePart.FeaturePropertyConstants.igRight, FiniteDepth: 0.005, Data: holeData); // Get a reference to the UserDefinedPatterns collection. userDefinedPatterns = model.UserDefinedPatterns; // Create the user defined pattern. userDefinedPattern = userDefinedPatterns.AddByProfiles( NumberOfProfiles: profileList.Count, ProfilesArray: profileList.ToArray(), SeedFeature: hole); // Get a reference to the ActiveSelectSet. selectSet = application.ActiveSelectSet; // Empty ActiveSelectSet. selectSet.RemoveAll(); // Add new UserDefinedPattern to ActiveSelectSet. selectSet.Add(userDefinedPattern); // Switch to ISO view. application.StartCommand(SolidEdgeConstants.SheetMetalCommandConstants.SheetMetalViewISOView); } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { SolidEdgeCommunity.OleMessageFilter.Unregister(); } }
public static void CreateHolesWithUserDefinedPattern(SolidEdgePart.PartDocument partDocument) { SolidEdgePart.RefPlanes refplanes = null; SolidEdgePart.RefPlane refplane = null; SolidEdgePart.Models models = null; SolidEdgePart.Model model = null; SolidEdgePart.HoleDataCollection holeDataCollection = null; SolidEdgePart.ProfileSets profileSets = null; SolidEdgePart.ProfileSet profileSet = null; SolidEdgePart.Profiles profiles = null; SolidEdgePart.Profile profile = null; SolidEdgePart.Holes2d holes2d = null; SolidEdgePart.Hole2d hole2d = null; SolidEdgePart.Holes holes = null; SolidEdgePart.Hole hole = null; long profileStatus = 0; List <SolidEdgePart.Profile> profileList = new List <SolidEdgePart.Profile>(); SolidEdgePart.UserDefinedPatterns userDefinedPatterns = null; SolidEdgePart.UserDefinedPattern userDefinedPattern = null; // Get a reference to the RefPlanes collection. refplanes = partDocument.RefPlanes; // Get a reference to front RefPlane. refplane = refplanes.GetFrontPlane(); List <double[]> linesArray = new List <double[]>(); linesArray.Add(new double[] { 0, 0, 0.08, 0 }); linesArray.Add(new double[] { 0.08, 0, 0.08, 0.06 }); linesArray.Add(new double[] { 0.08, 0.06, 0.064, 0.06 }); linesArray.Add(new double[] { 0.064, 0.06, 0.064, 0.02 }); linesArray.Add(new double[] { 0.064, 0.02, 0.048, 0.02 }); linesArray.Add(new double[] { 0.048, 0.02, 0.048, 0.06 }); linesArray.Add(new double[] { 0.048, 0.06, 0.032, 0.06 }); linesArray.Add(new double[] { 0.032, 0.06, 0.032, 0.02 }); linesArray.Add(new double[] { 0.032, 0.02, 0.016, 0.02 }); linesArray.Add(new double[] { 0.016, 0.02, 0.016, 0.06 }); linesArray.Add(new double[] { 0.016, 0.06, 0, 0.06 }); linesArray.Add(new double[] { 0, 0.06, 0, 0 }); // Call helper method to create the actual geometry. CreateFiniteExtrudedProtrusion(partDocument, refplane, linesArray.ToArray(), SolidEdgePart.FeaturePropertyConstants.igRight, 0.005); // Get a reference to the Models collection. models = partDocument.Models; // Get a reference to Model. model = models.Item(1); // Get a reference to the ProfileSets collection. profileSets = partDocument.ProfileSets; // Add new ProfileSet. profileSet = profileSets.Add(); // Get a reference to the Profiles collection. profiles = profileSet.Profiles; // Add new Profile. profile = profiles.Add(refplane); // Get a reference to the Holes2d collection. holes2d = profile.Holes2d; double[,] holeMatrix = new double[, ] { //{x, y} { 0.01, 0.01 }, { 0.02, 0.01 }, { 0.03, 0.01 }, { 0.04, 0.01 }, { 0.05, 0.01 }, { 0.06, 0.01 }, { 0.07, 0.01 } }; // Draw the Base Profile. for (int i = 0; i <= holeMatrix.GetUpperBound(0); i++) { // Add new Hole2d. hole2d = holes2d.Add( XCenter: holeMatrix[i, 0], YCenter: holeMatrix[i, 1]); } // Hide the profile. profile.Visible = false; // Close profile. profileStatus = profile.End(SolidEdgePart.ProfileValidationType.igProfileClosed); // Get a reference to the ProfileSet. profileSet = (SolidEdgePart.ProfileSet)profile.Parent; // Get a reference to the Profiles collection. profiles = profileSet.Profiles; // Add profiles to list for AddByProfiles(). for (int i = 1; i <= profiles.Count; i++) { profileList.Add(profiles.Item(i)); } // Get a reference to the HoleDataCollection collection. holeDataCollection = partDocument.HoleDataCollection; // Add new HoleData. SolidEdgePart.HoleData holeData = holeDataCollection.Add( HoleType: SolidEdgePart.FeaturePropertyConstants.igRegularHole, HoleDiameter: 0.005, BottomAngle: 90); // Get a reference to the Holes collection. holes = model.Holes; // Add hole. hole = holes.AddFinite( Profile: profile, ProfilePlaneSide: SolidEdgePart.FeaturePropertyConstants.igRight, FiniteDepth: 0.005, Data: holeData); // Get a reference to the UserDefinedPatterns collection. userDefinedPatterns = model.UserDefinedPatterns; // Create the user defined pattern. userDefinedPattern = userDefinedPatterns.AddByProfiles( NumberOfProfiles: profileList.Count, ProfilesArray: profileList.ToArray(), SeedFeature: hole); }
static void Main(string[] args) { SolidEdgeFramework.Application application = null; SolidEdgePart.SheetMetalDocument sheetMetalDocument = null; SolidEdgePart.FamilyMembers familyMembers = null; SolidEdgePart.Round round = null; SolidEdgePart.UserDefinedPattern userDefinedPattern = null; SolidEdgeFrameworkSupport.Dimension dimension = null; try { // Register with OLE to handle concurrency issues on the current thread. SolidEdgeCommunity.OleMessageFilter.Register(); // Connect to or start Solid Edge. application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true, true); // Bring Solid Edge to the foreground. application.Activate(); // Get a reference to the active part document. sheetMetalDocument = application.GetActiveDocument <SolidEdgePart.SheetMetalDocument>(false); if (sheetMetalDocument != null) { // Get a reference to the FamilyMembers collection. familyMembers = sheetMetalDocument.FamilyMembers; // Interate through the family members. foreach (var familyMember in familyMembers.OfType <SolidEdgePart.FamilyMember>()) { Console.WriteLine(familyMember.Name); // Determine FamilyMember MovePrecedence. switch (familyMember.MovePrecedence) { case SolidEdgePart.MovePrecedenceConstants.igModelMovePredecence: break; case SolidEdgePart.MovePrecedenceConstants.igSelectSetMovePrecedence: break; } // Warning: Accessing certain LiveRule[...] properties may throw an exception. //Console.WriteLine("igConcentricLiveRule - {0}", familyMember.LiveRule[SolidEdgePart.LiveRulesConstants.igConcentricLiveRule]); //Console.WriteLine("igCoplanarAxesAboutXLiveRule - {0}", familyMember.LiveRule[SolidEdgePart.LiveRulesConstants.igCoplanarAxesAboutXLiveRule]); //Console.WriteLine("igCoplanarAxesAboutYLiveRule - {0}", familyMember.LiveRule[SolidEdgePart.LiveRulesConstants.igCoplanarAxesAboutYLiveRule]); //Console.WriteLine("igCoplanarAxesAboutZLiveRule - {0}", familyMember.LiveRule[SolidEdgePart.LiveRulesConstants.igCoplanarAxesAboutZLiveRule]); //Console.WriteLine("igCoplanarAxesLiveRule - {0}", familyMember.LiveRule[SolidEdgePart.LiveRulesConstants.igCoplanarAxesLiveRule]); //Console.WriteLine("igCoplanarLiveRule - {0}", familyMember.LiveRule[SolidEdgePart.LiveRulesConstants.igCoplanarLiveRule]); //Console.WriteLine("igMaintainRadiusLiveRule - {0}", familyMember.LiveRule[SolidEdgePart.LiveRulesConstants.igMaintainRadiusLiveRule]); //Console.WriteLine("igOrthoLockingLiveRule - {0}", familyMember.LiveRule[SolidEdgePart.LiveRulesConstants.igOrthoLockingLiveRule]); //Console.WriteLine("igParallelLiveRule - {0}", familyMember.LiveRule[SolidEdgePart.LiveRulesConstants.igParallelLiveRule]); //Console.WriteLine("igPerpendicularLiveRule - {0}", familyMember.LiveRule[SolidEdgePart.LiveRulesConstants.igPerpendicularLiveRule]); //Console.WriteLine("igSymmetricLiveRule - {0}", familyMember.LiveRule[SolidEdgePart.LiveRulesConstants.igSymmetricLiveRule]); //Console.WriteLine("igSymmetricXYLiveRule - {0}", familyMember.LiveRule[SolidEdgePart.LiveRulesConstants.igSymmetricXYLiveRule]); //Console.WriteLine("igSymmetricYZLiveRule - {0}", familyMember.LiveRule[SolidEdgePart.LiveRulesConstants.igSymmetricYZLiveRule]); //Console.WriteLine("igSymmetricZXLiveRule - {0}", familyMember.LiveRule[SolidEdgePart.LiveRulesConstants.igSymmetricZXLiveRule]); //Console.WriteLine("igTangentEdgeLiveRule - {0}", familyMember.LiveRule[SolidEdgePart.LiveRulesConstants.igTangentEdgeLiveRule]); //Console.WriteLine("igTangentTouchingLiveRule - {0}", familyMember.LiveRule[SolidEdgePart.LiveRulesConstants.igTangentTouchingLiveRule]); //Console.WriteLine("igThicknessChainLiveRule - {0}", familyMember.LiveRule[SolidEdgePart.LiveRulesConstants.igThicknessChainLiveRule]); // Interate through the suppressed features of the current family member. for (int j = 1; j <= familyMember.SuppressedFeatureCount; j++) { object suppressedFeature = familyMember.SuppressedFeature[j]; // Use helper class to get the feature type. var featureType = SolidEdgeCommunity.Runtime.InteropServices.ComObject.GetPropertyValue <SolidEdgePart.FeatureTypeConstants>(suppressedFeature, "Type", (SolidEdgePart.FeatureTypeConstants) 0); switch (featureType) { case SolidEdgePart.FeatureTypeConstants.igRoundFeatureObject: round = (SolidEdgePart.Round)suppressedFeature; break; case SolidEdgePart.FeatureTypeConstants.igUserDefinedPatternFeatureObject: userDefinedPattern = (SolidEdgePart.UserDefinedPattern)suppressedFeature; break; } } // Interate through the variables of the current family member. for (int j = 1; j <= familyMember.VariableCount; j++) { object variable = familyMember.Variable[j]; // Use helper class to get the object type. var objectType = SolidEdgeCommunity.Runtime.InteropServices.ComObject.GetPropertyValue <SolidEdgeFramework.ObjectType>(variable, "Type", (SolidEdgeFramework.ObjectType) 0); switch (objectType) { case SolidEdgeFramework.ObjectType.igDimension: dimension = (SolidEdgeFrameworkSupport.Dimension)variable; break; } } } } else { throw new System.Exception("No active document."); } } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { SolidEdgeCommunity.OleMessageFilter.Unregister(); } }
static void Main(string[] args) { SolidEdgeFramework.Application application = null; SolidEdgeFramework.Documents documents = null; SolidEdgePart.SheetMetalDocument sheetMetalDocument = null; SolidEdgePart.RefPlanes refPlanes = null; SolidEdgePart.RefPlane refPlane = null; SolidEdgeFramework.SelectSet selectSet = null; Array features = Array.CreateInstance(typeof(object), 0); SolidEdgePart.ExtrudedProtrusion extrudedProtrustion = null; SolidEdgePart.UserDefinedPattern userDefinedPattern = null; SolidEdgePart.MirrorCopy mirrorCopy = null; try { // Register with OLE to handle concurrency issues on the current thread. SolidEdgeCommunity.OleMessageFilter.Register(); // Connect to or start Solid Edge. application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true, true); // Get a reference to the documents collection. documents = application.Documents; // Create a new sheet metal document. sheetMetalDocument = documents.AddSheetMetalDocument(); // Always a good idea to give SE a chance to breathe. application.DoIdle(); // Get a reference to the RefPlanes collection. refPlanes = sheetMetalDocument.RefPlanes; // Get a reference to the top RefPlane using extension method. refPlane = refPlanes.GetTopPlane(); // Get path to Solid Edge training directory. Typically, 'C:\Program Files\Solid Edge XXX\Training'. var trainingDirectory = new System.IO.DirectoryInfo(SolidEdgeCommunity.SolidEdgeUtils.GetTrainingFolderPath()); // Build path to source part document. //string LibName = System.IO.Path.Combine(trainingDirectory.FullName, "Foot1.psm"); string LibName = System.IO.Path.Combine(trainingDirectory.FullName, "base.par"); // This method will take all features from block.par and place them into the new part document. sheetMetalDocument.PlaceFeatureLibrary(LibName, refPlane, 0.0, 0.0, 0.0, out features); // Optionally, iterate through all of the added features. foreach (var feature in features.OfType <object>()) { // Use helper class to get the feature type. var featureType = SolidEdgeCommunity.Runtime.InteropServices.ComObject.GetPropertyValue <SolidEdgePart.FeatureTypeConstants>(feature, "Type", (SolidEdgePart.FeatureTypeConstants) 0); // Depending on the feature type, we can cast the weakly typed feature to a strongly typed feature. switch (featureType) { case SolidEdgePart.FeatureTypeConstants.igExtrudedProtrusionFeatureObject: extrudedProtrustion = (SolidEdgePart.ExtrudedProtrusion)feature; break; case SolidEdgePart.FeatureTypeConstants.igUserDefinedPatternFeatureObject: userDefinedPattern = (SolidEdgePart.UserDefinedPattern)feature; break; case SolidEdgePart.FeatureTypeConstants.igMirrorCopyFeatureObject: mirrorCopy = (SolidEdgePart.MirrorCopy)feature; break; } } // Get a reference to the ActiveSelectSet. selectSet = application.ActiveSelectSet; // Empty ActiveSelectSet. selectSet.RemoveAll(); // Add all features to ActiveSelectSet. foreach (object feature in features) { selectSet.Add(feature); } // Switch to ISO view. application.StartCommand(SolidEdgeConstants.SheetMetalCommandConstants.SheetMetalViewISOView); } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { SolidEdgeCommunity.OleMessageFilter.Unregister(); } }
static void CreateHolesWithUserDefinedPattern(SolidEdgePart.SheetMetalDocument sheetMetalDocument) { SolidEdgePart.RefPlanes refplanes = null; SolidEdgePart.RefPlane refplane = null; SolidEdgePart.Models models = null; SolidEdgePart.Model model = null; SolidEdgePart.HoleDataCollection holeDataCollection = null; SolidEdgePart.ProfileSets profileSets = null; SolidEdgePart.ProfileSet profileSet = null; SolidEdgePart.Profiles profiles = null; SolidEdgePart.Profile profile = null; SolidEdgePart.Holes2d holes2d = null; SolidEdgePart.Hole2d hole2d = null; SolidEdgePart.Holes holes = null; SolidEdgePart.Hole hole = null; long profileStatus = 0; List <SolidEdgePart.Profile> profileList = new List <SolidEdgePart.Profile>(); SolidEdgePart.UserDefinedPatterns userDefinedPatterns = null; SolidEdgePart.UserDefinedPattern userDefinedPattern = null; // Get a reference to the RefPlanes collection. refplanes = sheetMetalDocument.RefPlanes; // Get a reference to Right (yz) plane. refplane = refplanes.Item(3); // Get a reference to the Models collection. models = sheetMetalDocument.Models; // Get a reference to Model. model = models.Item(1); // Get a reference to the ProfileSets collection. profileSets = sheetMetalDocument.ProfileSets; // Add new ProfileSet. profileSet = profileSets.Add(); // Get a reference to the Profiles collection. profiles = profileSet.Profiles; // Add new Profile. profile = profiles.Add(refplane); // Get a reference to the Holes2d collection. holes2d = profile.Holes2d; // This creates a cross pattern of holes. double[,] holeMatrix = new double[, ] { //{x, y} { 0.00, 0.00 }, { -0.01, 0.00 }, { -0.02, 0.00 }, { -0.03, 0.00 }, { -0.04, 0.00 }, { 0.01, 0.00 }, { 0.02, 0.00 }, { 0.03, 0.00 }, { 0.04, 0.00 }, { 0.00, -0.01 }, { 0.00, -0.02 }, { 0.00, -0.03 }, { 0.00, -0.04 }, { 0.00, 0.01 }, { 0.00, 0.02 }, { 0.00, 0.03 }, { 0.00, 0.04 } }; // Draw the Base Profile. for (int i = 0; i <= holeMatrix.GetUpperBound(0); i++) { // Add new Hole2d. hole2d = holes2d.Add( XCenter: holeMatrix[i, 0], YCenter: holeMatrix[i, 1]); } // Hide the profile. profile.Visible = false; // Close profile. profileStatus = profile.End(SolidEdgePart.ProfileValidationType.igProfileClosed); // Get a reference to the ProfileSet. profileSet = (SolidEdgePart.ProfileSet)profile.Parent; // Get a reference to the Profiles collection. profiles = profileSet.Profiles; // Add profiles to list for AddByProfiles(). for (int i = 1; i <= profiles.Count; i++) { profileList.Add(profiles.Item(i)); } // Get a reference to the HoleDataCollection collection. holeDataCollection = sheetMetalDocument.HoleDataCollection; // Add new HoleData. SolidEdgePart.HoleData holeData = holeDataCollection.Add( HoleType: SolidEdgePart.FeaturePropertyConstants.igRegularHole, HoleDiameter: 0.005, BottomAngle: 90); // Get a reference to the Holes collection. holes = model.Holes; // Add hole. hole = holes.AddFinite( Profile: profile, ProfilePlaneSide: SolidEdgePart.FeaturePropertyConstants.igRight, FiniteDepth: 0.005, Data: holeData); // Get a reference to the UserDefinedPatterns collection. userDefinedPatterns = model.UserDefinedPatterns; // Create the user defined pattern. userDefinedPattern = userDefinedPatterns.AddByProfiles( NumberOfProfiles: profileList.Count, ProfilesArray: profileList.ToArray(), SeedFeature: hole); }