I may have a project coming up, and I am not a super programmer. If I were to have a shape like shown:
Where the profile could be just 1 as shown or subdivided up into x pieces, how would one go about telling the software to take the shape and make the required panels to fill this profile? I know I can get the count and items, but I just dont know the code to loop or do what needs to be done to make each instance? If its too complicated to explain, I get it. I was just curious.
Gelöst! Gehe zur Lösung
Gelöst von Curtis_Waguespack. Gehe zur Lösung
Yes it's possible but an Ilogic sketch linked to some parameters more than likely can take care of this for you. All while avoiding the script or code.
I still wrote something up for you. We do not have the ability to pattern within the sketch environment using Ilogic. So the math and what not has to be baked into the program in some way. This will ask you to enter the number of panels you'd like to place. Then divide or pattern the points and lines that get created inside.
The code below can be copied into an empty part file then ran. It will give you similar results to the attached photo.
Sub main()
Dim oDoc As PartDocument = ThisApplication.ActiveDocument
Dim oCompDef As PartComponentDefinition = oDoc.ComponentDefinition
Dim oTO As TransientObjects = ThisApplication.TransientObjects
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
'Setup variables for holding information from user.
Dim TotalPanels As Integer = InputBox("How many panels would you like? " & " Panel selection ")
Dim TotalLength As Double = Nothing
Dim osketch As PlanarSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes.Item(2))
Dim oCenter as SketchPoint = osketch.AddByProjectingEntity(oCompDef.WorkAxes.Item(2))
Dim RightPoint As SketchPoint = osketch.SketchPoints.Add(oTG.CreatePoint2d(oCenter.Geometry.X - 12 * 2.54, oCenter.Geometry.Y))
Dim RightPointCon As GeometricConstraint = osketch.GeometricConstraints.AddHorizontalAlign(oCenter, RightPoint)
'Create the main top line.
Dim FirstLine As SketchLine = osketch.SketchLines.AddByTwoPoints(RightPoint, oCenter)
Dim FirstLineDim As DimensionConstraint = osketch.DimensionConstraints.AddTwoPointDistance(FirstLine.StartSketchPoint, FirstLine.EndSketchPoint, kAlignedDim, oTG.CreatePoint2d(-15, 15))
'Get the distance of this line and pass it into the total value, if inputted from a form or user input this would not be needed.
TotalLength = FirstLineDim.Parameter.Value
'Create the left side longer line
Dim LeftLinePoint As SketchPoint = osketch.SketchPoints.Add(oTG.CreatePoint2d(oCenter.Geometry.X, oCenter.Geometry.Y + 16 * 2.54))
Dim LeftLinePointCon As GeometricConstraint = osketch.GeometricConstraints.AddVerticalAlign(LeftLinePoint, oCenter)
Dim LeftLine As SketchLine = osketch.SketchLines.AddByTwoPoints(FirstLine.EndSketchPoint, LeftLinePoint)
Dim LeftLineDim As DimensionConstraint = osketch.DimensionConstraints.AddTwoPointDistance(LeftLine.StartSketchPoint, LeftLine.EndSketchPoint, kAlignedDim, oTG.CreatePoint2d(20, 20))
'Create the right side shorter line.
Dim RightLinePoint As SketchPoint = osketch.SketchPoints.Add(oTG.CreatePoint2d(RightPoint.Geometry.X, RightPoint.Geometry.Y + 10 * 2.54))
Dim RightLinePointCon As GeometricConstraint = osketch.GeometricConstraints.AddVerticalAlign(RightPoint, RightLinePoint)
Dim RightLine As SketchLine = osketch.SketchLines.AddByTwoPoints(FirstLine.StartSketchPoint, RightLinePoint)
Dim RightLineDim As DimensionConstraint = osketch.DimensionConstraints.AddTwoPointDistance(RightLine.StartSketchPoint, RightLine.EndSketchPoint, kAlignedDim, oTG.CreatePoint2d(-15, -15))
'Create the angled line between the two lines.
Dim AngledLine As SketchLine = osketch.SketchLines.AddByTwoPoints(RightLine.EndSketchPoint, LeftLine.EndSketchPoint)
'Now we get tricky, but we need to get some math done first.
Dim Sectionwidth As Double = TotalLength / TotalPanels
Dim StartingLength As Integer = 1 * 2.54
Dim CurrentXPos As Double = RightLine.StartSketchPoint.Geometry.Y - Sectionwidth
Dim i As Integer = 0
While i < TotalPanels - 1
Dim oPointA As SketchPoint = osketch.SketchPoints.Add(oTG.CreatePoint2d(CurrentXPos, RightLine.StartSketchPoint.Geometry.Y))
'The below dimension holds the line at its creation location
Dim oPointALoc As DimensionConstraint = osketch.DimensionConstraints.AddTwoPointDistance(oPointA, RightLine.StartSketchPoint, kAlignedDim, oTG.CreatePoint2d(20, 20))
Dim oPointB As SketchPoint = osketch.SketchPoints.Add(oTG.CreatePoint2d(CurrentXPos, RightLine.StartSketchPoint.Geometry.Y + StartingLength))
'This creates the lines between the point objects.
Dim oLineA As SketchLine = osketch.SketchLines.AddByTwoPoints(oPointA, oPointB)
'Control the angle after the distance to then constrain to lines
Dim AngleControl as DimensionConstraint = osketch.DimensionConstraints.AddTwoLineAngle(FirstLine, oLineA, oTG.CreatePoint2d(15, 15))
Dim oPointBCon As GeometricConstraint = osketch.GeometricConstraints.AddCoincident(oPointB, AngledLine)
Dim oPointACon As GeometricConstraint = osketch.GeometricConstraints.AddCoincident(oPointA, FirstLine)
i = i + 1
'Update the new position value for the next iteration.
CurrentXPos = CurrentXPos - Sectionwidth
End While
End Sub
So this code will go and auto generate each component panel to make the overall shape? That is what I was kind of looking for. Not necessarily just a sketch? For instance, this side panel would be controlled by an upper level assembly set of questions such as: Side Overall Length, Y height, Y1 height, etc. User enters in the desired values, and if it exceeds the panel size, then it would break it down and auto populate the panels. I know it is pretty involved, or at least it sounds like it to me lol.
You're on the track I was on a year or so ago. Sounds like you're messing about with some sheet metal panels for a spray booth or something. Either way you've got a maximum size for a sheet.
Without knowing exactly what it is you're doing I'm not sure where to take the code. However, yes you can make a form that allows each of these items to change depending on what you need. For example, where I set the distances in this program could be switched out with parameters the users input. Then depending on those inputs you can add conditions for division if a sheet is too large.
I used to mess with cyclone collectors made of sheet metal. I would check each panel size against the maximum our plas table could cut. If the panel was larger I added another division to the sheet or item. All of that stuff will be dependent on your companies individual needs.
Attached is the part itself. I moved the input into a form controlled by parameters. You can now play around with the size spacing and whatnot of this entire shape.
A full program to convert all of that into correct sized panels will be quite the undertaking. Possible yes, unlikely anyone can whip something up without a large amount of internal data or understanding of your needs.
I might now be explaining it correctly, but how do I make the software see, Oh I have 3 panels. Take the sub-divided skeleton and extrude the first profile, then do a save as and make a new component, and an now make the second profile, etc. Does that make sense? So that way I now have 3 independent parts created?
You're starting to interact with many components of the API that would require many levels of navigation. To do something like this it would take me a good half a day just researching how to get from one point to another in order to gain the correct information at the different levels. Then another half a day or more to program it's implementation.
The first hurdle is you're going to be driving, saving, renaming, and storing the parts one by one. As the API does not have access to the standard "make components" or "design assistant" function of the software. This means you would need to create the panel then extrude or face each solid under it's own surface body. Then using those surface bodies you would derive a part from them, save to a folder under a new name. Then later look to pull those parts back into an assembly if needed.
What you want to do is possible, just more than what I was originally solving for. Hopefully we get some others in here to provide you some clearer insights. I'm at my limit due to not directly interacting with derived components yet. We need someone who's messed with that portion of the software for their own uses. They'll have a better idea how to navigate this portion of the API.
That is what I figured, I was just confirming. Thank for your efforts.
See attached 2022 version
( the code needed an update to work in 2025, so I went ahead and did that in 2022 in case others w/ older versions were interested)
open the assembly and run the rule called "Split" to see this work
What is the purpose of this in the main mart rule called SplitPart?:
Dim oLength As Double
oMin = oDef.Features.ExtrudeFeatures.Item(1).RangeBox.MinPoint.Y
oMax = oDef.Features.ExtrudeFeatures.Item(1).RangeBox.MaxPoint.Y
oLength = (oMax - oMin) * 0.3937007874
It's just getting the overall length of the feature, which in this example is the same as the length of the part, and converting it to inches since that is the part units
search that rule for oLength, and you'll find where it is using this variable to ensure the user hasn't tried to create an invalid split by entering a split distance past the end of the part.
I was reading through and noticed that. Why would one obtain the length like that vs just grabbing the length parameter? Advantages? I always see things like this and I have to ask lol
But its nice, works. Thanks for posting.
Sie finden nicht, was Sie suchen? Fragen Sie die Community oder teilen Sie Ihr Wissen mit anderen.