Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A sketchpoint issue #116

Open
Brent-bai opened this issue Nov 7, 2023 · 6 comments
Open

A sketchpoint issue #116

Brent-bai opened this issue Nov 7, 2023 · 6 comments
Assignees

Comments

@Brent-bai
Copy link

Brent-bai commented Nov 7, 2023

Point point = new Point(X,Y,0.0);
swSketchPoint = (ISwSketchPoint)sketch2D.Entities.PreCreatePoint();
swSketchPoint.Coordinate = point;
sketch2D.Entities.Add(swSketchPoint);

This code cause sw app crashing with no reason.
I change the code to solidworks api as below:

SketchManager swSketchMgr = (SketchManager)swModel.SketchManager;
Sketch swSketch = swSketchMgr.ActiveSketch;
swSketchMgr.CreatePoint(x, y, 0.0);
swModel.ClearSelection2(true);
swModel.GraphicsRedraw();

It also cause the app crashing. The CreatPoint() throw a exception: "This is often an indication that other memory is corrupt.”
I ask the ChatGpt, it changed the code to:

SketchManager swSketchMgr = (SketchManager)swModel.SketchManager;
Sketch swSketch = swSketchMgr.ActiveSketch;
swModel.ClearSelection2(true);
swModel.SetAddToDB(true);
swSketchMgr.CreatePoint(x, y, 0.0);
swModel.SetAddToDB(false);
swModel.GraphicsRedraw();

I noticed the code adding a SetAddToDB() method, and it worked. I wonder that xcad.net api having considered this issue.

@Brent-bai
Copy link
Author

I create a minium environment, only click a command to run above function, they all work well. In my code, first creat a sketch, then click a command to start a poperty manager page, as I click one button of the page to run the first code above, the sw app crashed. It seemes sw crashing when returning to my command page.
Then I add the AddHorizontalDimension2() to the third code above, the sw app crashed again. It is highly suspected that a memory access issue occurred when the sketching tool's property manager switched back to my property manager page.

@Brent-bai
Copy link
Author

I'm sure it does cause by my pmp closing when sketchtool raising. This command may not use pmp.

@Brent-bai
Copy link
Author

There is a constance "OPTS_DEFAULT" in internal Show() which in Internal class PropertyManagerPagePage of Xarial.XCad.SolidWorks.UI.PropertyPage.Toolkit.Controls, it allow the other page to be a StackPage. Make it to a page attribute may resolve this issue.

@artem1t artem1t self-assigned this Nov 8, 2023
@artem1t
Copy link
Contributor

artem1t commented Nov 8, 2023

Yes, that makes sense to add an option to have StackPage. I will add one.

Regarding the sketch. Yes, AddToDB is used: https://github.com/xarial/xcad/blob/!dev/src/SolidWorks/Sketch/SwSketchEntityCollection.cs#L73C2-L89

But if I am not mistaken this was added into the pre-release version (e.g. 8.X and not available in 7.X)

@Brent-bai
Copy link
Author

I have changed "OPTS_DEFAULT = 1", it does not worked. The property manager page will not being closed when I click the OK or Cancle button. Here is my sample code:
SketchCreateTest.zip

@Brent-bai
Copy link
Author

Brent-bai commented Nov 27, 2023

I used lockedPage attribue ([PageOptions(PageOptions_e.LockedPage)]) option to resolve the problem, avoiding the crashing of sw when inserting a point and adding dimension. But unfortunately in this option, the SelectById2 method will not work. Because some sketch points are com_object, it can not use Select4 method to select the point. It seems I have tried all the way, but I can't find the right answer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants