is there a way to get drawing view centerline underlying sketch to control its length?
I need to grab its ends (just like you do it manually by grabbing blue squares after clicking on centerline) and then, extend them.
i cant find anything.
no access through IAnnotation
Cannot be cast to anything else.
you can get the location data from
but this doesn't help you.
2016 SOLIDWORKS API Help - GetLineAtIndex3 Method (IDisplayData)
even recording a macro doesnt give you any information that is helpful
using IView.GetSketch doesn't even work.
thank you for doing your best, i did the same stuff that you are mentioning, did some research, some google finds, still no luck at all.
Appears that no one else had the same problem as me before, maybe its not even implemented in SW api
first you select view after that , by using GetLine4() you get the details of your Line for eg. LINETYPE , Start & end Point co-ordinate .
But i don't know to change Start & end Point Co-ordinate of CenterLine . if you got it then please informe me .
depending on what type of sketch segment it is, you will basically need to get the start and end points. see below
2017 SOLIDWORKS API Help - GetStartPoint2 Method (ISketchLine)
2017 SOLIDWORKS API Help - GetEndPoint2 Method (ISketchLine)
2017 SOLIDWORKS API Help - X Property (ISketchPoint)
2017 SOLIDWORKS API Help - Y Property (ISketchPoint)
2017 SOLIDWORKS API Help - Z Property (ISketchPoint)
Unfortunately, your suggestion is completely wrong.
How can i get lines in view, when centerline is a display data object, not a sketch?
try this short macro with preselecting drawing view with centerline in it:
Dim swApp As SldWorks.SldWorks
Dim swmodel As SldWorks.ModelDoc2
Dim swselmgr As SldWorks.SelectionMgr
Dim swView As SldWorks.View
Set swApp = Application.SldWorks
Set swmodel = swApp.ActiveDoc
Set swselmgr = swmodel.SelectionManager
Set swView = swselmgr.GetSelectedObject6(1, -1)
You will have 0 in line count, if you will identify selected object by GetSelectedObjectType3 Method (ISelectionMgr) and centerline preselected, you will have swSelCENTERLINES as your return type.
When you will try to assign centerline object thru ICenterLine, there is no way to get underlying sketch of this centerline, because it is display data object, not a sketch, you can get display data object start and end points, but there is no way to change it.
Check this, its work .
swViews = swDoc.GetFirstView();
swViews = swViews.GetNextView();
while (swViews != null)
// swViews = swSelMg.GetSelectedObject5(1);
swViews.ScaleRatio = swScale;
double BoundaryBox = swViews.GetOutline();
double Xmin = BoundaryBox;
double Xmax = BoundaryBox;
double XvalueForCenterLine = (Xmax + Xmin) / 2;
double Ymin = BoundaryBox;
double Ymax = BoundaryBox;
double YvalueForCenterLine = (Ymax + Ymin) / 2;
double OutBox = swViews.GetOutline();
int count = swViews.GetLineCount2(1);
Debug.Print("count" + count);
if (count != 0)
double centerLine = swViews.GetLines4(1);
Sketch swSketch = swViews.GetSketch();
Object vswSketch = swSketch.GetSketchSegments();
int j = vswSketch.Length;
for (int i = 0; i < j; i++)
SketchSegment swSketchSeg = (SketchSegment)vswSketch[i];
// SketchLine Line = swSketchSeg
swModel.EditDelete(); // Delete line then Create New One .
SketchManager swSketchMg = swModel.SketchManager;
swSketchMg.CreateCenterLine(-XvalueForCenterLine, 0, 0, XvalueForCenterLine,0,0); // if center line is Horizontal
Note : - its is only Hoeizontal CenterLine ,
ok, as far I can understand your code, you are creating new centerline by swSketchMg.CreateCenterLine, thing is, i do not want to create new one based on old ones, or view.outline, i need to extend preselected ones to specified length, therefore I am searching for a way to do it.
Creating new centerlines thru sketch manager generates another problems that i want to avoid.
you cannot record doing this. chances are solidworks doesnt have an api for it.
Retrieving data ...