gadgets

This section is for general discussion about Gadgets
Post Reply
Mikeyd
Posts: 4
Joined: Wed Dec 30, 2020 9:59 pm
Model of CNC Machine: Cobot 15000

gadgets

Post by Mikeyd »

hello i would like to create a gadget for: selecting an imported file, and rotate 90 ° ,and then set it back to x 0 y 0. is there anyone who can help me i'm stuck on the point rotation and set it back on x0 y0

User avatar
Adrian
Vectric Archimage
Posts: 11699
Joined: Thu Nov 23, 2006 2:19 pm
Model of CNC Machine: ShopBot PRS Alpha 96x48
Location: Surrey, UK

Re: gadgets

Post by Adrian »

You've asked this question in three different areas which can make it pretty tricky to keep track of replies etc. Better to ask once and wait for replies. There aren't many people creating gadgets so responses aren't as fast as other parts of the forum.

Assuming it is vectors you want to rotate you need to look at the Transform method in the SDK documentation.

Mikeyd
Posts: 4
Joined: Wed Dec 30, 2020 9:59 pm
Model of CNC Machine: Cobot 15000

Re: gadgets

Post by Mikeyd »

Hello Adrian,

First of all: best wishes for 2021! :)

Thanks for your help by pointing in the direction of the SDK documentation.
Together with my brother-in-law, we created some code, which already works nice for the rotation of the vectors/objects.
However, the re-setting of the x / y axis does not seem to do anything.

Here is the full code:

Code: Select all

-- VECTRIC LUA SCRIPT
function main()
	job = VectricJob()
	if not job.Exists then
		DisplayMessageBox("No job loaded")
		return false;
	end

	local selection = job.Selection
	-- eerst roteren
	if selection.IsEmpty then
		MessageBox("Please select one or more vectors to label")
		return false
	else
		--MessageBox(tostring(selection.Count))
		if selection:CanTransform(2) then
			local xform = RotationMatrix2D(Point2D(0,0), 90)
			selection:Transform(xform)
		end
	end
	-- dan verschuiven
	local selection2 = job.Selection
	if selection.IsEmpty then
		MessageBox("Please select one or more vectors to label")
		return false
	else
		--MessageBox(tostring(selection.Count))
		if selection:CanTransform(1) then
			local vec = Vector2D(0.0, 0.0)
			local xform2 = TranslationMatrix2D(vec)
			selection:Transform(xform2)
		end	
	end
	job:Refresh2DView()
	return true
end
First of all: are we right to use the TranslationMatrix2D please?
If so, have you any more suggestions on what we should change please?
The exact action I want to simulate from Vcarve Pro is 'transform objects' -> 'move selected objects' -> 'absolute, x: 0.0 and y:0.0'

Have a great day!

User avatar
Adrian
Vectric Archimage
Posts: 11699
Joined: Thu Nov 23, 2006 2:19 pm
Model of CNC Machine: ShopBot PRS Alpha 96x48
Location: Surrey, UK

Re: gadgets

Post by Adrian »

The translation matrix isn't an absolute value it's a distance to move. So you need to create your input to TransformMatrix2D as the distance in XY you need to move the bottom left (presuming that's what you want to be at 0,0) of your selected vector to 0,0.

Post Reply