0% found this document useful (0 votes)
18 views

Solved_ Use Trim option by C# api - Autodesk Community

INVENTOR API Tutorial

Uploaded by

강성용
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Solved_ Use Trim option by C# api - Autodesk Community

INVENTOR API Tutorial

Uploaded by

강성용
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

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 = partDef.Sketches.Add(partDef.WorkPlanes[3]);
TransientGeometry tg = default(TransientGeometry); Solution 1
tg = ThisApplication.TransientGeometry;

Line1 = sketch.SketchLines.AddByTwoPoints(tg.CreatePoint2d(0, 10), tg.CreatePoint2d(-20, 10)); Solution 2


Line2 = sketch.SketchLines.AddByTwoPoints(tg.CreatePoint2d(-20, 10), tg.CreatePoint2d(-15, 0));
Line3 = sketch.SketchLines.AddByTwoPoints(tg.CreatePoint2d(0, 10), tg.CreatePoint2d(0, 5));
Line4 = sketch.SketchLines.AddByTwoPoints(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

Line4.IntersectWithCurve(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 VB.NET

Dim oLineSegment01 As LineSegment2d


oLineSegment01 = oSketchLine01.Geometry

C# maybe

LineSegment2d oLineSegment01 =oSketchLine01.Geometry

 Report

 0 Likes Reply

‎06-10-2022 01:19 AM


Michael.Navara

Accepted solution

Here is a sample code for something like Trim Function


1 var pick1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchCurveLinearFilter, "Pick line 1");
2 var pick2 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchCurveLinearFilter, "Pick line 2");
3 SketchLine line1 = pick1 as SketchLine;
4 SketchLine line2 = pick2 as SketchLine;
5
6 var intersectWithCurve = line1.Geometry.IntersectWithCurve(line2.Geometry);
7 foreach (var o in intersectWithCurve)
8 {
9 if (o is Point2d pt2d)
10 {
11 var geometricConstraints = line1.Parent.GeometricConstraints;
12 var line1StartSketchPoint = line1.StartSketchPoint;
13 var line1EndSketchPoint = line1.EndSketchPoint;
14
15 var distanceFromStart = line1StartSketchPoint.Geometry.DistanceTo(pt2d);
16 var distanceFromEnd = line1EndSketchPoint.Geometry.DistanceTo(pt2d);
17
18 if (distanceFromStart > distanceFromEnd)
19 {
20 line1EndSketchPoint.MoveTo(pt2d);
21 geometricConstraints.AddCoincident(line1EndSketchPoint as SketchEntity, line2 as SketchEntity);
22 }
23 else
24 {
25 line1StartSketchPoint.MoveTo(pt2d);
26 geometricConstraints.AddCoincident(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

You might also like