Cyclone Python

Discuss and upload any tools here for other members to use.
Post Reply
I have made 20-30 posts
I have made 20-30 posts
Posts: 28
Joined: Mon Aug 03, 2015 12:24 pm
Full Name: S R
Company Details: Unknown
Company Position Title: Helper
Country: France
Linkedin Profile: No

Cyclone Python

Post by KirbX »

Hello everybody,
I'm not sure that this is the good place to ask this question but I didn't find better...

I am actually working to do some Python programs for Cyclone, and was wondering if there is a way to wait passively for an keyboard input. I mean I want to create a program that allows the user to pick all the objects he wants, then press a key and then the program copy-paste all the items he picked before everytime he click somewhere.
But I can't find a way to wait for the user to press button without losing the fact that he can click on the ModelSpace.

I'm not sure someone understand me, and i'm sorry for my bad english, but if you have question/answer, i'm here ;)

Have a nice day all! :=)
User avatar
Global Moderator
Global Moderator
Posts: 1777
Joined: Sun Aug 12, 2007 9:22 pm
Full Name: Steven Ramsey
Company Details: 4DMax
Company Position Title: Technical Specialist Scanning
Country: UK
Skype Name: steven.ramsey
Linkedin Profile: Yes
Location: London
Has thanked: 23 times
Been thanked: 19 times

Re: Cyclone Python

Post by stevenramsey »

Bad English, Way better than my French. As per your last thread I hope Bill may be able to point you in the right direction.

Are you able to share your code to others, you could start a nice little exchange program of scripts.
Steven Ramsey

Home [email protected]
Work [email protected]
Mobile +44 7766 310 915
V.I.P Member
V.I.P Member
Posts: 140
Joined: Thu Oct 29, 2009 11:14 pm
Full Name: Bill Wallace
Company Details: Leica Geosystems
Company Position Title: HDS Sr. Software Product Manager

Re: Cyclone Python

Post by Bill-Wallace »

I am not so sure myself about the keyboard entry intercepts, I'll see if I can look into that. From the work I have done, I do know it is easy to do what you describe but have a dialog box button to press when you want to execute, after selecting items.

Have you considered that? It should be shown how to do this in the samples and documentation.
I have made 20-30 posts
I have made 20-30 posts
Posts: 28
Joined: Mon Aug 03, 2015 12:24 pm
Full Name: S R
Company Details: Unknown
Company Position Title: Helper
Country: France
Linkedin Profile: No

Re: Cyclone Python

Post by KirbX »

I considerated the fact that I could do a dialog box, but only tried with a Textbox where you write something when you want to end, but again, this textbox is active and i'm not able to click some points with the textbox opened.
edit : It's probably normal, I will try right now with a dialog box

I will modify a little my code to make sure you won't throw up seiing it (i'm still a beginner with Python and I think my code isn't as beautiful as I wanted it to be ;) ), and to correct the few bug I did (thanks Python to be that explicit when pointing up an error <3 :) )

But thanks for your response and i'll contact you again soon! :)
I have made 20-30 posts
I have made 20-30 posts
Posts: 28
Joined: Mon Aug 03, 2015 12:24 pm
Full Name: S R
Company Details: Unknown
Company Position Title: Helper
Country: France
Linkedin Profile: No

Re: Cyclone Python

Post by KirbX »

Hello all, it's me again :
My work isn't working as I want him to work (sad life of a newbie programmer ;) ),
the problem is situated in the last lines of my code (that you can find below)
(I actually put ... on function that are useless, but if you want me to give the complete code, I can do it)
It's probably not the better code you'll see on your life, but it works a little.

Code: Select all

# Brief
#This program should allow the user to create stair easily.
#First step : pick all the geom he wants ( not finished yet )
#then the item is cloned to another one that can be moved using a form (x,y,z axis)
#when the clone is well placed, indicate the number of step you wants
#and the script copy-paste the clone already create nbr times.

import System.Drawing
import System.Windows.Forms
import LeicaGeosystems.LinearAlgebra
import LeicaGeosystems.PrivateUtilities

from System.Drawing import *
from System.Windows.Forms import *
from LeicaGeosystems.LinearAlgebra import *
from LeicaGeosystems.PrivateUtilities import *

import sys
print sys.path

from ctypes import (windll, Structure, sizeof, WINFUNCTYPE, pointer, byref, c_uint, c_int, c_char)
from ctypes.wintypes import (HWND, HANDLE, HBRUSH, LPCWSTR, WPARAM, LPARAM, MSG, RECT)
user32 = windll.user32

#Used to always have a copy of geom i'm working on
pick_geom = None
created_geom = None
clone_geom = None
# ######################

# movement of the created first clone object that will be used to move all the steps of the stair
glb_x = 0.0
glb_y = 0.0
glb_z = 0.0
# ######################

#Form for the number of step you want ((actually not used))
class nbr(Form):

#Form for the movement of the first clone (on X,Y and Z Axis. )
#Appliquer will aplicate the movement, and pressing ok will (normally) continue the script/
class fenetre(Form):
	def __init__(self, x, y, z):
		#movement of the cloned item
		self.axe_x = 0.0
		self.axe_y = 0.0
		self.axe_z = 0.0
		#Origin_x, Origin_y, Origin_z, Origin of the clicked geom
		self.o_x = x
		self.o_y = y
		self.o_z = z
		self.numberX_valide = True;
		self.numberY_valide = True;
		self.numberZ_valide = True;
		self.ok = False;
		self.done = False;
	def InitializeComponent(self):
	def Button_OKClick(self, sender, e):
		self.ok = True;
		self.done = True;
		if (clone_geom != None):
			self.axe_x = clone_geom.Origin.X
			self.axe_y = clone_geom.Origin.Y
			self.axe_z = clone_geom.Origin.Z
	def Button_CancelClick(self, sender, e):
	def Button_ApplyClick(self, sender, e):
		global glb_x, glb_y, glb_z;
		if (clone_geom != None):
			created_geom.Move(float(self._textbox_X.Text) * Vector3D.XAxis)
			created_geom.Move(float(self._textbox_Y.Text) * Vector3D.YAxis)
			created_geom.Move(float(self._textbox_Z.Text) * Vector3D.ZAxis)
			glb_x += float(self._textbox_X.Text)
			glb_y += float(self._textbox_Y.Text)
			glb_z += float(self._textbox_Z.Text)
	def fentreClosed(self, sender, e):
		self.done = True;
		self.ok = False;
	def TextBox_XValidating(self, sender, e):
	def TextBox_YValidating(self, sender, e):
	def TextBox_ZValidating(self, sender, e):
	def fenetreLoad(self,sender, e):
		self._textbox_X.Text = str(self.axe_x)
		self._textbox_Y.Text = str(self.axe_y)
		self._textbox_Z.Text = str(self.axe_z)
	def UpdateButtons(self, sender, e):
except  NameError:
	__run_from_cyclone__ = False;
print "run from Cyclone :" + str(__run_from_cyclone__);

if (__run_from_cyclone__):
	all_geoms = []
	#Pick the item you want to be the first step ever
	pick_geom=_cy_pick.PickSingleGeom("Pickez un objet :", ["all"], "picked geom")
	#take its Origin
	init_x = pick_geom.Origin.X
	init_y = pick_geom.Origin.Y
	init_z = pick_geom.Origin.Z
	#Cloning him
	clone_geom = _cy_geom_factory.Clone(pick_geom)
	#The point where you want to create the clone
	pick_point = _cy_pick.PickAny("Selectionnez un point:")
	mv_x = pick_point.X
	mv_y = pick_point.Y
	mv_z = pick_point.Z
	#the vector between the point you clicked and the origin
	sub_x = mv_x - init_x
	sub_y = mv_y - init_y
	sub_z = mv_z - init_z
	glb_x = sub_x
	glb_y = sub_y
	glb_z = sub_z
	#It's a try to move the clone already at the better place possible
	#But it's not really usefull actually 
	clone_geom.Move(sub_z * Vector3D.ZAxis)
	if (sub_x < sub_y):
		clone_geom.Move(sub_y * Vector3D.YAxis)
		clone_geom.Move(sub_x * Vector3D.XAxis)
	created_geom = _cur_model_space.CreateGeom(clone_geom, clone_geom.DisplayName);

	#We created the clone, now we can move it
	dialog = fenetre(created_geom.Origin.X, created_geom.Origin.Y, created_geom.Origin.Z);
	dialog.Title = "Create Escalator"
	inputViaConsole = _cy_status.InputViaConsole;
	msg = MSG()
	lpmsg = pointer(msg)
	while user32.GetMessageW(byref(msg), 0, 0, 0) != 0 and dialog.done == False:
	#Since i put dialog.ok on true when i click on OK it should do the statement.
	#But it seems that it doesn't care and don't wait for the user to click on OK
	#And it only do the job 3 times instead of 10
	if (dialog.ok == True):
		for i in range(1,10):
			stair = _cy_geom_factory.Clone(created_geom)
			stair.Move(i * glb_x * Vector3D.XAxis)
			stair.Move(i * glb_y * Vector3D.YAxis)
			stair.Move(i * glb_z * Vector3D.ZAxis)
			create_stair = _cur_model_space.CreateGeom(stair, stair.DisplayName)
If you see something, i'm here!
Thanks all :)

Edit : I found my "error" and i'm stupid :cry:
now it works but it can be waaaaaaay better ...
Have a nice end of day all :)
Post Reply

Return to “AutoLisp, Dynamo, VBA, Python & .Net Tools”