I am developing a tool in QGIS 3.16.2 and python 3.7 where i want to make a tool where i can identify any arbitrary point on the map canvas layer, which i already achieved. But when i select any point on the map canvas i want the drop down to only show points and not line and polygons too (see pictures further down).
The code i used to make map identify tool working is as follows:
def choose_a_point(self):
self.canvas = self.iface.mapCanvas()
self.identify_vector = QgsMapToolIdentify(self.canvas)
self.identify_vector.canvasReleaseEvent = self.store_m_value
self.canvas.setMapTool(self.identify_vector)
# Execute function that stores identified point info
def store_m_value(self, event):
result = self.identify_vector.identify(event.x(), event.y(), [], QgsMapToolIdentify.DefaultQgsSetting)
# Check if the selected feature is a point!
if result[0].mFeature.geometry().type() == QgsWkbTypes.PointGeometry:
if result:
pass # Do something useful here
When i click on a point in the map canvas i get following dropdown (seams like this function is built in to the QgsMapToolIdentify:
But i want to get the following result, so the lines and polygons are removed from the dropdown list:
I tried looking at the documentation for QgsMapToolIdentify on this page QT documentation - , but with no luck.
Hope someone can help me fix this problem.
Related
I use OCC with python to visualize .igs and .stl format. In .stl file I have a mesh on my model and I want to know what vertex on this mesh was clicked. At least to get some kind of id. I see that the model that I choose automatically highlights without any settings, so I guess there is a way to do this. But I couldn’t find any information about it.
Okay, found it. In case someone else will need it:
display = self.occWidget._display
display.SetSelectionModeVertex() # This is the required function
display.register_select_callback(recognize_clicked)
where recognize_clicked is
def recognize_clicked(shp, *kwargs):
""" This is the function called every time
a face is clicked in the 3d view
"""
for shape in shp:
print("Face selected: ", shape)
Face selection - SetSelectionModeFace()
Vertex selection - SetSelectionModeVertex()
Edge selection - SetSelectionModeEdge()
Shape selection - SetSelectionModeShape()
Neutral (default) selection - SetSelectionModeNeutral()
That is all the modes that I've found in other examples. Please, if you find more, write in a comment that resource.
I'm new to tkiinter and i didn't manage to find a solution to my problem on internet.
First thing I need to draw a sort of table with triangles similar to the one in this picture (https://www.tilelook.com/system/tile_picture/resource/4973584/d3d_default_RE04MC017.png).
Then the user can choose a color somewhere (from a list or something similar) and change the color of a triangle by clicking on it. The most important thing is that i need to retrieve these information in the code (for each trinagle I need to know which color the user choosed).
Edit:
I still didn't write any code, but i know how to draw the table with Canvas and more or less how to handle the coloring part. The hard part for me is how to retrieve the informations in the code, I think it's like considering each element of the table like an independent object or something like that, but i have no idea how to do it.
I won't give you a complete solution but you may find the below a helpful starting point
import tkinter as tk
from random import choice
def getRandomColor():
return choice(['red','blue','green','yellow','white','goldenrod'])
def click(event):
print(vars(event))
item = event.widget.find_withtag('current')
event.widget.itemconfig(item,fill=getRandomColor())
root = tk.Tk()
root.grid()
c = tk.Canvas(root,width=300,height=300,bg='black')
c.grid()
c.create_polygon(0,0,100,0,50,100,fill='blue',tag='tri_1')
c.create_polygon(100,0,50,100,150,100,fill='yellow',tag='tri_2')
c.bind('<Button-1>',click)
root.mainloop()
This will create two triangles. If you click on a triangle it will change to a random color (from a small list of colors).
This will give you some ideas about
a. drawing polygons on a tkinter canvas
b. binding a function to a click
c. changing the properties of a canvas item
Hope you find this helpful
I'm learning maya scripting from recent days and got confused about how to apply custom manipulator with user defined context. Select the obj and click Show Manipulator Tool doesn't work. This question maybe stupid but I just cannot find out how to do it.
There is an example in the devkit filmMoveManip.py and I wanna know how to use it. I know how to load it, just the way how to get the manipulator shown and use it.
add the script filmMoveManip.py to your plugin_path and follow the usage guide in the file header:
# filmMoveManip.py
# Scripted plug-in that displays a manipulator that
# modifies the film translate horizontal and vertical
# values.
#
# To use this plug-in:
# 1. execute the following Python:
# import maya
# maya.cmds.loadPlugin("filmMoveManip.py")
# maya.cmds.spFilmMoveManipCtxCmd( 'spFilmMoveManipContext1' )
# maya.cmds.setParent( 'Shelf1' )
# maya.cmds.toolButton( 'spFilmMoveManip1', cl='toolCluster', t='spFilmMoveManipContext1', i1="filmMoveManip.xpm" )
# 2. Open the outliner and select a camera shape such as perspShape
# 3. A manipulator with a horizontal and vertical axis will be displayed.
# 4. Move the axis to modify the film translate
I have a bunch of poly vertex components selected. But sometimes users might select something else along with it (a joint, another mesh, etc.). I'm trying to find a way to test against everything selected to verify it is indeed a vertex. But I can't find anything like this.
Is there a python command to do this directly?
It may be useful for your use-case to use filterExpand with the selectionMask flag set to 31 to return just polygon vertex components from everything that has been selected.
Following is a simple sample (with some comments):
Try it out with different kind of objects and components selected.
import maya.cmds as cmds
# Will return EVERYTHING selected
all_selected = cmds.ls(sl=True)
# Will filter out and return just the verts
# from everything selected
just_the_selected_verts = cmds.filterExpand(sm=31)
Check out filterExpand in the docs here.
Not exactly. You can find objects which are ready for component selection with cmds.ls(hl=True). You can find selected object which aren't components with cmds.ls(o=True). That means you can isolate only the component selections indirectly like this:
set (cmds.ls(sl=True, o=False)) - set(cmds.ls(sl=True, o=True))
which makes a set of the whole selection, then one with only the objects, and finally subtracts the second from the first leaving only the component selections (note that will also pass attribute selections if you have those).
This is my little Python programm Using Vpython
I want to rotate a box.
I want to use the boxes axis and not the one of the scene.
so for example if its rotated to the right and then i want to get the "nose" down, i want to do this in the view of the box...
imagine i was a jet ;)
BTW: I´m a python 3
from visual import *
a=box(size=(5,1,3),axis=(1,0,0))
def tasten():
"Looooopings "
if scene.kb.keys: #action on keyboard?
druck=scene.kb.getkey() #save to cache
if druck=='left':
a.rotate(angle=-1/100, axis=(1,0,0)) #links drehen
if druck=='right':
a.rotate(angle=1/100, axis=(1,0,0)) #rechts drehen
if druck=='up':
a.rotate(angle=-1,axis=(0,0,1)) #nose down
while True:
tasten()
I would recommend creating a box class that stores the orientation, as martineau is suggesting. The class would have a vector that stores its orientation, then a method to rotate it in whatever way required.