Sign in
Autodesk Community Products Support Learn Community Education
Autodesk Community / Inventor Community / Inventor Programming - iLogic, Macros, AddIns & Apprentice / Use Trim option by C# api
Use Trim option by C# api Options
IT-Fundilusa Explorer 06-09-2022 07:13 AM
Hello,
Reply
I need to use the Trim by code option, I create lines in a Sketch line1, line2, line3 and line4.
I need to trim line 4 from the end of the line to the intersection with line 2
Code:
Accepted solutions (2)
PlanarSketch sketch = default(PlanarSketch);
sketch = [Link]([Link][3]);
TransientGeometry tg = default(TransientGeometry); Solution 1
tg = [Link];
Line1 = [Link](tg.CreatePoint2d(0, 10), tg.CreatePoint2d(-20, 10)); Solution 2
Line2 = [Link](tg.CreatePoint2d(-20, 10), tg.CreatePoint2d(-15, 0));
Line3 = [Link](tg.CreatePoint2d(0, 10), tg.CreatePoint2d(0, 5));
Line4 = [Link](tg.CreatePoint2d(0, 5), tg.CreatePoint2d(-20, 5));
466 Views
6 Replies
trim_line.png178 KB
Report
Reply
Replies (6)
06-09-2022 07:25 AM
florian_wenzel
Hi,
i think there is no API Methode for Trim in Sketch.
Correct me if im wrong.
But you can Create new line using the Intersection Points.
The Result is similary
Report
0 Likes Reply
06-09-2022 07:27 AM
IT-Fundilusa
How do I get the point of intersection of two lines?
Report
0 Likes Reply
06-09-2022 07:31 AM
florian_wenzel in reply to IT-Fundilusa
[Link](Line2,)
Report
0 Likes Reply
06-09-2022 07:39 AM
IT-Fundilusa
The type of line4 is SketchLine and the does not have this function.
Report
0 Likes Reply
06-09-2022 07:51 AM
florian_wenzel in reply to IT-Fundilusa
Accepted solution
Change the SketchLine into LineSegment2d.
Inventor 2022 Help | LineSegment2d Object | Autodesk
Here a sample in [Link]
Dim oLineSegment01 As LineSegment2d
oLineSegment01 = [Link]
C# maybe
LineSegment2d oLineSegment01 =[Link]
Report
0 Likes Reply
06-10-2022 01:19 AM
[Link]
Accepted solution
Here is a sample code for something like Trim Function
1 var pick1 = [Link]([Link], "Pick line 1");
2 var pick2 = [Link]([Link], "Pick line 2");
3 SketchLine line1 = pick1 as SketchLine;
4 SketchLine line2 = pick2 as SketchLine;
5
6 var intersectWithCurve = [Link]([Link]);
7 foreach (var o in intersectWithCurve)
8 {
9 if (o is Point2d pt2d)
10 {
11 var geometricConstraints = [Link];
12 var line1StartSketchPoint = [Link];
13 var line1EndSketchPoint = [Link];
14
15 var distanceFromStart = [Link](pt2d);
16 var distanceFromEnd = [Link](pt2d);
17
18 if (distanceFromStart > distanceFromEnd)
19 {
20 [Link](pt2d);
21 [Link](line1EndSketchPoint as SketchEntity, line2 as SketchEntity);
22 }
23 else
24 {
25 [Link](pt2d);
26 [Link](line1StartSketchPoint as SketchEntity, line2 as SketchEntity);
27 }
28 }
29 }
VBA Object Browser for Inventor | iLogic for VisualStudio | Inventor AddIn Debugger
Report
2 Likes Reply
Reply to the topic... Post Reply
↑ Back to top
Report a website issue
Autodesk How to buy Support
Autodesk Foundation
Company overview View all products Product support
Sustainability
Careers Buying with Autodesk Manage your account
Contact us
Investor relations Renewal options Download and install software
Students and educators
Autodesk Trust Center Find a reseller Autodesk Product Status
Affiliate program
Newsroom Sales and refunds Education support
Autodesk Research
Diversity and belonging Choose your subscription plan Contact support
Design & Make with Autodesk
LA28 Games Pay as you go with Flex
Privacy | Do not sell or share my personal information | Cookie preferences | Report noncompliance | Terms of use | Legal | © 2024 Autodesk Inc. All rights reserved