Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Issue with Automating Break Creation in iLogic

6 REPLIES 6
Reply
Message 1 of 7
mat_hijs
411 Views, 6 Replies

Issue with Automating Break Creation in iLogic

I have an issue with creating breaks in iLogic. More specifically I have an issue with creating multiple breaks. When I create one break it works perfectly, the break ends up in the correct position. But when I try to create a second break on the same view I can't get the position right.

What I'm trying to do is the following: I have a part that has some notches in it, one is always in the middle, and the others are always at the same spacing from the middle, both left and right. The amount of notches would depend on the length of the part. I want to show all the notches on my drawing, but I want to remove the spaces between them with breaks to make everything fit on my sheet. The first break I place is placed correctly, no matter if it is break 1 or break 2. The second one is not placed correctly as you can see in the attached images.

I attached a (dummy) part and a drawing that includes the rule I'm using. Could anyone tell me how the first break is impacting the second break and how I could account for that?

 

6 REPLIES 6
Message 2 of 7
aelqabbany
in reply to: mat_hijs

I don't have any code handy, but I've run into this issue before. After you perform the first break, the width of the view decreases, therefore the points that you want to pass into your second break are now incorrect.
The solution is to offset the points for your second break by the change in the view width.

For example:
Original view width = 50
View width after first break = 45
Change = 50 - 45 = 5

Therefore you need to subtract 5 from each of your second break points.
Message 3 of 7
mat_hijs
in reply to: aelqabbany

I understand that the view gets less wide, but how can I find out how much? Should I try to get the view width again after every break?

Message 4 of 7
aelqabbany
in reply to: mat_hijs

That's how I did it if I remember correctly. It wasn't very efficient, but it worked.
You could probably figure out how much the view would decrease by calculating the difference between the points of the first break, and subtracting that number from the points of the second break. It might be slightly faster as it requires less API calls.
Message 5 of 7

There is the break distance that you specify and then some constant. You need to get the new view width but also take into account that you need to use the distance from the start of the view.

 

I was using the following code but the code was not necessary anymore so I also stopped at some point. 

 

It might require some tweaking of the +/- defaultGap etc (and its c#), but below might help. I was creating multiple horizontal breaks in a long view. The BreakInfo class has the startCoord and the breakLength in 'mm'. The startcoord is the distance from the minimum x to the start of the break. 

 

 

 

       public static void CreateBreakOperation(DrawingView v) // List<BreakInfo> breaks, 
        {
            var dwg = (DrawingDocument)Inv.Application.ActiveDocument;
            var sht = dwg.ActiveSheet;

            var tg = Inv.Application.TransientGeometry;

            foreach (BreakOperation breakOp in v.BreakOperations)
            {
                breakOp.Delete();
            }

            // define the breakoperations 
            var breakInfos = new List<BreakInfo>()
            {
                new BreakInfo(100.0,100.0),
                new BreakInfo(300.0,100.0),
                new BreakInfo(600.0,200.0),
            };

            // break the view at specified locations
            var previousGaps = 0.0;
            var i = 1;
            foreach (var breakInfo in breakInfos)
            {
                Logger.Info($"Width before break {i} = {v.Width * 10} mm");

                // calculate new left x coord of view
                var leftPoint = v.Center.X - v.Width / 2;
                Logger.Info($"Left point X: {leftPoint}");

                // calculate new starting coord taking into account previous breaks
                double newStartCoord = breakInfo.StartCoord - previousGaps;
                double scaled = (newStartCoord * v.Scale);
                Logger.Info($"previous gaps: {previousGaps}");
                Logger.Info($"new start coord: {newStartCoord}");
                Logger.Info($"new start coord scaled: {scaled}");

                // determine start/endpoint factoring in the scale
                // gap should not be scaled
                var startPoint = tg.CreatePoint2d(leftPoint + scaled, v.Center.Y);
                var endPoint = tg.CreatePoint2d(leftPoint + scaled + (breakInfo.BreakLength * v.Scale) + (breakInfo.DefaultGap) / 2 , v.Center.Y);

                Logger.Info($"break info: startpoint = {breakInfo.StartCoord}, length {breakInfo.BreakLength}");

                var mSpaceStartPoint = tg.CreatePoint(0, 0, breakInfo.StartCoord);
                var vSpaceStartPoint = v.ModelToSheetSpace(mSpaceStartPoint);

                // calculate new starting coord taking into account previous breaks
                var actualStartPoint = tg.CreatePoint2d(vSpaceStartPoint.X, v.Center.Y);
                var actualEndPoint = tg.CreatePoint2d(vSpaceStartPoint.X + (breakInfo.BreakLength * v.Scale), v.Center.Y);

                Logger.Info($"actual startpoint: x = {actualStartPoint.X}, y = {actualStartPoint.Y}");
                Logger.Info($"actual endpoint: x = {actualEndPoint.X}, y = {actualEndPoint.Y}");

                Logger.Info($"adjusted startpoint: x = {startPoint.X}, y = {startPoint.Y}");
                Logger.Info($"adjusted endpoint: x = {endPoint.X}, y = {endPoint.Y}");

                // add the break operation with default values
                v.BreakOperations.Add(BreakOrientationEnum.kHorizontalBreakOrientation,
                    startPoint,
                    endPoint,
                    BreakStyleEnum.kStructuralBreakStyle);

                Logger.Info($" ======= ");


                // add this gap to previous gaps to start the next break at the right position
                previousGaps += breakInfo.BreakLength;
                i++;
            }
        }
    }

    public class BreakInfo
    {
        public double DefaultGap = .6;
        public double StartCoord;
        public double BreakLength;

        public BreakInfo(double startCoord, double breakLength)
        {
            StartCoord = startCoord;
            BreakLength = breakLength;
        }
    }

 

 

 

 

 

 

Contact me for custom app development info@basautomationservices.com. Follow below links to view my Inventor appstore apps.

Free apps: Reset view Representations | Smart Leader | Copy with Constraints | Part Visibility Utility | Property Editor | Mate Origins

Paid apps: Frame Stiffener Tool | Constrain Plane Toggle


Message 6 of 7

Any chance you could help me convert this to something usable in iLogic? I have never used C# so it would take a very long time for me to convert it by myself, if I even manage to do it.

Message 7 of 7

Something like this should do:

 

I have changed the BreakInfo class to a list of double arrays with 2 values. The first being the start coordinate and the second the break length. It should consider scale and the breaking gap. You can change this to take any amount of double arrays as input. 


There is no error catching or anything, if the break exceeds the view an error will be thrown.

        
		
		Dim dwg = CType(ThisApplication.ActiveDocument, DrawingDocument)
        Dim sht = dwg.ActiveSheet
        Dim tg = ThisApplication.TransientGeometry
		Dim v = sht.DrawingViews.Item(1)
		Dim defaultGap = 0.6

        For Each breakOp As BreakOperation In v.BreakOperations
            breakOp.Delete()
        Next
		
        Dim breakInfos = New List(Of Double())() From {
            New Double() {25.0, 50.0},
            New Double() {100.0, 50.0},
            New Double() {180.0, 50.0}
        }
		
        Dim previousGaps = 0.0
        Dim i = 1

        For Each breakInfo In breakInfos
            Dim leftPoint = v.Center.X - v.Width / 2

            Dim newStartCoord As Double = breakInfo(0) - previousGaps
            Dim scaled As Double = (newStartCoord * v.Scale)

            Dim startPoint = tg.CreatePoint2d(leftPoint + scaled, v.Center.Y)
            Dim endPoint = tg.CreatePoint2d(leftPoint + scaled + (breakInfo(1) * v.Scale) + (defaultGap) / 2, v.Center.Y)

            Dim mSpaceStartPoint = tg.CreatePoint(0, 0, breakInfo(0))
            Dim vSpaceStartPoint = v.ModelToSheetSpace(mSpaceStartPoint)
			
            Dim actualStartPoint = tg.CreatePoint2d(vSpaceStartPoint.X, v.Center.Y)
            Dim actualEndPoint = tg.CreatePoint2d(vSpaceStartPoint.X + (BreakInfo(1) * v.Scale), v.Center.Y)

            v.BreakOperations.Add(BreakOrientationEnum.kHorizontalBreakOrientation, startPoint, endPoint, BreakStyleEnum.kStructuralBreakStyle)
            previousGaps += breakInfo(1)
            i += 1
        Next

 

Let me know if you need more help

Contact me for custom app development info@basautomationservices.com. Follow below links to view my Inventor appstore apps.

Free apps: Reset view Representations | Smart Leader | Copy with Constraints | Part Visibility Utility | Property Editor | Mate Origins

Paid apps: Frame Stiffener Tool | Constrain Plane Toggle


Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report