[SOLVED] Snapping restrictions

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
Taygete
Full Member
Posts: 50
Joined: Wed May 14, 2014 8:53 am

[SOLVED] Snapping restrictions

Post by Taygete » Wed Feb 25, 2015 9:20 am

Hi Andrew,

I was wondering if there is a way to switch on snapping restrictions from within a script without the user having to select the restriction from the snap tools palette?

I can see you allow a user to enable the restrict angle length in the Line2P.js script but this is enabled via a button on the toolbar, I would like to enable this so it is always on in my script without the need for the user to enable it.

Thanks,

Andrew.
Last edited by Taygete on Tue Mar 24, 2015 9:14 am, edited 1 time in total.

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: Snapping restrictions

Post by andrew » Mon Mar 02, 2015 1:53 pm

You can use setSnapRestriction through the document interface:
di.setSnapRestriction(new RRestrictAngleLength(di));

Taygete
Full Member
Posts: 50
Joined: Wed May 14, 2014 8:53 am

Re: Snapping restrictions

Post by Taygete » Fri Mar 20, 2015 12:36 pm

Hi Andrew,

Thanks for the guidance.

I had tried this previously but without success, so I tried again but it still doesn't add the "Restrict Angle or Length" ui components to my tools optionsbar. The only way I can get it too work is if I physically click the option from the CAD Tools bar.

I was hoping I could add the "Restrict Angle or Length" ui components to my tools optionsbar in code so the user doesn't need to click the restriction in the CAD Tool bar, should I be doing something else as well?

Thanks,

Andrew.

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: Snapping restrictions

Post by andrew » Sat Mar 21, 2015 11:03 am

Taygete wrote:it still doesn't add the "Restrict Angle or Length" ui components to my tools optionsbar.
No. This sets the restriction mode for the document. UI components are handled on a different level entirely.
I was hoping I could add the "Restrict Angle or Length" ui components to my tools optionsbar
You could trigger the restriction tool programmatically (this is user interface level stuff):
var guiAction = RGuiAction.getByScriptFile("scripts/Snap/RestrictAngleLength/RestrictAngleLength.js");
guiAction.trigger();

Taygete
Full Member
Posts: 50
Joined: Wed May 14, 2014 8:53 am

Re: Snapping restrictions

Post by Taygete » Sat Mar 21, 2015 8:32 pm

Hi Andrew,

Thanks for the information.

That got me a bit closer, the "Restrict Angle or Length" button in the CADTools is highlighted however I still don't get the "Restrict Angle or Length" ui components added to my tools optionsbar until I click the "Restrict Angle or Length" button on the CADTools.

I guess I must be doing something wrong but can't see what at the moment.

Thanks,

Andrew.

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: Snapping restrictions

Post by andrew » Mon Mar 23, 2015 9:10 am

I see. Don't remember from the top of my head how that is implemented. Can you try:
di.setSnapRestriction(new RRestrictAngleLengthExtension(di));

Taygete
Full Member
Posts: 50
Joined: Wed May 14, 2014 8:53 am

Re: Snapping restrictions

Post by Taygete » Tue Mar 24, 2015 9:14 am

Hi Andrew,

Thanks for the info.

It worked okay this time, I had tried calling setSnapRestriction previously on an earlier build of QCAD (version 3.6.1 I think) and couldn't get it to work however it works fine on 3.9.1.

I also needed to include the RestrictAngleLength.js script

Code: Select all

include("scripts/Snap/RestrictAngleLength/RestrictAngleLength.js");
otherwise RRestrictAngleLengthExtension is unrecognised.

Thanks,

Andrew.

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”