Anyway to highlight the assembly constraints?
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Anyway to highlight the assembly constraints?
It would be useful if we could visually inspect the assembly constraints like we do for sketch constraints:
---
Do we currently have such a possibility?
---
Do we currently have such a possibility?
Assembly 3 notes: https://github.com/ceremcem/freecad-notes
- HarryGeier
- Veteran
- Posts: 1231
- Joined: Mon Jul 10, 2017 12:36 pm
- Location: Hof Germany
Re: Anyway to highlight the assembly constraints?
Not that i know ..in Assembly2 . If you are much into assemblies.. maybe hook into the assembly3 thread, which seems to be the future of assembly in FreeCAD. Assembly2 is not actively beeing developed.
https://forum.freecadweb.org/viewtopic. ... &start=300
https://forum.freecadweb.org/viewtopic. ... &start=300
Kaum macht man´s richtig , gehts´s
My Video Tutorials on Youtube: https://www.youtube.com/channel/UCoe3B ... p8Q/videos
My FreeCAD Stuff on Hidrive: https://my.hidrive.com/share/qr3l1yddy6#$/
My Video Tutorials on Youtube: https://www.youtube.com/channel/UCoe3B ... p8Q/videos
My FreeCAD Stuff on Hidrive: https://my.hidrive.com/share/qr3l1yddy6#$/
Re: Anyway to highlight the assembly constraints?
Hello ceremcem,
i think it is simple to modify assembly2 by yourself.
I am already working with an modified version, which i did last time.
At short: You have to extend freecad a little bit. I created a new command with i copied to importpart.py, which is located in your mod-folder and there within the assembly2 folder.
here is the code for the command-extension:
The command turns all parts of the assembly to transparency and highlights the components of an selected constraint.
I dont have much time at the moment and have to leave the house within a few minutes, shortly i will tell you more...
p.s.: PLEASE PROVIDE YOUR SYSTEMINFORMATION...
regards,
Klaus
i think it is simple to modify assembly2 by yourself.
I am already working with an modified version, which i did last time.
At short: You have to extend freecad a little bit. I created a new command with i copied to importpart.py, which is located in your mod-folder and there within the assembly2 folder.
here is the code for the command-extension:
Code: Select all
class ViewConnectionsCommand:
def Activated(self):
selection = [s for s in FreeCADGui.Selection.getSelection() if s.Document == FreeCAD.ActiveDocument ]
if len(selection) == 0: return
FreeCADGui.Selection.clearSelection()
doc = FreeCAD.ActiveDocument
connectionToView = selection[0]
if not 'ConstraintInfo' in connectionToView.Content and not 'ConstraintNfo' in connectionToView.Content:
return # Selected Object is not a connection/constraint
# Save Transparency of Objects and make all transparent
transparencyList = []
for obj in doc.Objects:
if hasattr(obj,'ViewObject'):
if hasattr(obj.ViewObject,'Transparency'):
transparencyList.append(obj.ViewObject.Transparency)
obj.ViewObject.Transparency = 80
FreeCADGui.Selection.addSelection(
doc.getObject(connectionToView.Object1),
connectionToView.SubElement1
)
FreeCADGui.Selection.addSelection(
doc.getObject(connectionToView.Object2),
connectionToView.SubElement2
)
#FreeCADGui.SendMsgToActiveView("ViewSelection") # not good enough
flags = QtGui.QMessageBox.StandardButton.Yes
msg = "Close Connection ViewMode ?"
response = QtGui.QMessageBox.information(QtGui.qApp.activeWindow(), "Highlighting ready", msg, flags )
# restore transparency of objects...
i=0
for obj in doc.Objects:
if hasattr(obj,'ViewObject'):
if hasattr(obj.ViewObject,'Transparency'):
obj.ViewObject.Transparency = transparencyList[i]
i+=1
FreeCADGui.Selection.clearSelection()
FreeCADGui.Selection.addSelection(selection[0])
def GetResources(self):
return {
'Pixmap' : a3lib.pathOfModule()+'/icons/a3_viewConnection.svg',
'MenuText': 'show connected elements',
'ToolTip': 'show connected elements'
}
FreeCADGui.addCommand('a3_ViewConnectionsCommand', ViewConnectionsCommand())
I dont have much time at the moment and have to leave the house within a few minutes, shortly i will tell you more...
p.s.: PLEASE PROVIDE YOUR SYSTEMINFORMATION...
regards,
Klaus
KBWBE
https://github.com/kbwbe/A2plus
latest release: v0.4.56, installable via FreeCAD's addon manager
Tutorial: gripper assembly https://www.youtube.com/watch?v=QMxcQ5tssWk
Documentation: https://www.freecadweb.org/wiki/A2plus_Workbench
https://github.com/kbwbe/A2plus
latest release: v0.4.56, installable via FreeCAD's addon manager
Tutorial: gripper assembly https://www.youtube.com/watch?v=QMxcQ5tssWk
Documentation: https://www.freecadweb.org/wiki/A2plus_Workbench
Re: Anyway to highlight the assembly constraints?
Helle kbwbe,
I am also intested in this 'highlighting'-feature.
At 1st I copied the importpart.py (just in case)...
I tried your modification (I added your code to the importpart.py)
I restarted Freecad and tried assembly2.. And I got this message..?
Actually: there IS a way to show constraints (but it takes a few clicks)
https://forum.freecadweb.org/viewtopic.php?f=22&t=26546
OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.16.6712 (Git)
Build type: Release
Branch: releases/FreeCAD-0-16
Hash: da2d364457257a7a8c6fb2137cea12c45becd71a
Python version: 2.7.8
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 6.8.0.oce-0.17
I am also intested in this 'highlighting'-feature.
At 1st I copied the importpart.py (just in case)...
I tried your modification (I added your code to the importpart.py)
I restarted Freecad and tried assembly2.. And I got this message..?
Actually: there IS a way to show constraints (but it takes a few clicks)
https://forum.freecadweb.org/viewtopic.php?f=22&t=26546
OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.16.6712 (Git)
Build type: Release
Branch: releases/FreeCAD-0-16
Hash: da2d364457257a7a8c6fb2137cea12c45becd71a
Python version: 2.7.8
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 6.8.0.oce-0.17
Re: Anyway to highlight the assembly constraints?
Hello Koemi,
sorry, i could finish my complete explanation yesterday because lack of time.
From your system-information i see that you are using windows. (i am using linux only, do not have a windows machine)
Therefore i adapted my script which you have to copy to importpart.py a little bit and removed my icon. (which can not bee found in your system)
Here is the new code, but please follow the copy instructions afterwards...
The errormessage you have got is simple. The programming language python is very sensitive to identation of the codelines.
I think somethings got wrong with copying and inserting of my codefragment. Or the place was a wrong one.
I installed assembly2 again and copied the code exactly before this place in importpart.py (within a few empty lines):
Because Python is so sensitive to identations, the modified importpart.py file has to look finally like:
This modification only implements the new command, but it is not automaticaly accessible. You need an icon or button in the toolbar of assembly2.
Because I deactivated my icon, you will get a button in the toolbar if you add one line and a comma-separator to the file InitGui.py (i marked the changes within the code).
Please find it here:
After modification of this two files, you have to start FreeCAD again. On Linux, it works for me with assembly2.
I see the new button in the toolbar of assembly2:
I select a constraint within my assembly...
and hit the new button:
Everything becomes transparently and you can have a look at the constraint. The two involved parts are hightlighted in the tree view...
Quit the dialog and everything looks like before.
Hope this helps (and urgently waiting for the next generation assembly....),
regards,
Klaus
P.S: Unfortunately you have to hit an extra button
sorry, i could finish my complete explanation yesterday because lack of time.
From your system-information i see that you are using windows. (i am using linux only, do not have a windows machine)
Therefore i adapted my script which you have to copy to importpart.py a little bit and removed my icon. (which can not bee found in your system)
Here is the new code, but please follow the copy instructions afterwards...
Code: Select all
class ViewConnectionsCommand:
def Activated(self):
selection = [s for s in FreeCADGui.Selection.getSelection() if s.Document == FreeCAD.ActiveDocument ]
if len(selection) == 0: return
FreeCADGui.Selection.clearSelection()
doc = FreeCAD.ActiveDocument
connectionToView = selection[0]
if not 'ConstraintInfo' in connectionToView.Content and not 'ConstraintNfo' in connectionToView.Content:
return # Selected Object is not a connection/constraint
# Save Transparency of Objects and make all transparent
transparencyList = []
for obj in doc.Objects:
if hasattr(obj,'ViewObject'):
if hasattr(obj.ViewObject,'Transparency'):
transparencyList.append(obj.ViewObject.Transparency)
obj.ViewObject.Transparency = 80
FreeCADGui.Selection.addSelection(
doc.getObject(connectionToView.Object1),
connectionToView.SubElement1
)
FreeCADGui.Selection.addSelection(
doc.getObject(connectionToView.Object2),
connectionToView.SubElement2
)
#FreeCADGui.SendMsgToActiveView("ViewSelection") # not good enough
flags = QtGui.QMessageBox.StandardButton.Yes
msg = "Close Connection ViewMode ?"
response = QtGui.QMessageBox.information(QtGui.qApp.activeWindow(), "Highlighting ready", msg, flags )
# restore transparency of objects...
i=0
for obj in doc.Objects:
if hasattr(obj,'ViewObject'):
if hasattr(obj.ViewObject,'Transparency'):
obj.ViewObject.Transparency = transparencyList[i]
i+=1
FreeCADGui.Selection.clearSelection()
FreeCADGui.Selection.addSelection(selection[0])
def GetResources(self):
return {
#'Pixmap' : a3lib.pathOfModule()+'/icons/a3_viewConnection.svg',
'MenuText': 'show constraint',
'ToolTip': 'show constraint'
}
FreeCADGui.addCommand('a3_ViewConnectionsCommand', ViewConnectionsCommand())
I think somethings got wrong with copying and inserting of my codefragment. Or the place was a wrong one.
I installed assembly2 again and copied the code exactly before this place in importpart.py (within a few empty lines):
Code: Select all
if __name__ == '__main__':
Code: Select all
#a lot of code above...
debugPrint(3,' leaving %s.%s as is, since subElement in old and new shape are equal' % (c.Name, SubElement))
class ViewConnectionsCommand:
def Activated(self):
selection = [s for s in FreeCADGui.Selection.getSelection() if s.Document == FreeCAD.ActiveDocument ]
if len(selection) == 0: return
FreeCADGui.Selection.clearSelection()
doc = FreeCAD.ActiveDocument
connectionToView = selection[0]
if not 'ConstraintInfo' in connectionToView.Content and not 'ConstraintNfo' in connectionToView.Content:
return # Selected Object is not a connection/constraint
# Save Transparency of Objects and make all transparent
transparencyList = []
for obj in doc.Objects:
if hasattr(obj,'ViewObject'):
if hasattr(obj.ViewObject,'Transparency'):
transparencyList.append(obj.ViewObject.Transparency)
obj.ViewObject.Transparency = 80
FreeCADGui.Selection.addSelection(
doc.getObject(connectionToView.Object1),
connectionToView.SubElement1
)
FreeCADGui.Selection.addSelection(
doc.getObject(connectionToView.Object2),
connectionToView.SubElement2
)
#FreeCADGui.SendMsgToActiveView("ViewSelection") # not good enough
flags = QtGui.QMessageBox.StandardButton.Yes
msg = "Close Connection ViewMode ?"
response = QtGui.QMessageBox.information(QtGui.qApp.activeWindow(), "Highlighting ready", msg, flags )
# restore transparency of objects...
i=0
for obj in doc.Objects:
if hasattr(obj,'ViewObject'):
if hasattr(obj.ViewObject,'Transparency'):
obj.ViewObject.Transparency = transparencyList[i]
i+=1
FreeCADGui.Selection.clearSelection()
FreeCADGui.Selection.addSelection(selection[0])
def GetResources(self):
return {
#'Pixmap' : a3lib.pathOfModule()+'/icons/a3_viewConnection.svg',
'MenuText': 'show constraint',
'ToolTip': 'show constraint'
}
FreeCADGui.addCommand('a3_ViewConnectionsCommand', ViewConnectionsCommand())
if __name__ == '__main__':
print('\nTesting importPart.py')
def test_split_and_join( pathLib, path):
print('Testing splitting and rejoining. lib %s' % (str(pathLib)))
parts = path_split( pathLib, path )
print(' parts %s' % parts )
print(' rejoined %s' % path_join(pathLib, parts ) )
print(' original %s' % path )
test_split_and_join( ntpath, 'C:/Users/gyb/Desktop/Circular Saw Jig\Side support V1.00.FCStd')
test_split_and_join( ntpath, 'C:/Users/gyb/Desktop/Circular Saw Jig/Side support V1.00.FCStd')
test_split_and_join( posixpath, '/temp/hello1/foo.FCStd')
def test_path_convert( path, pathLibFrom, pathLibTo):
print('Testing path_convert_lib.')
print(' original %s' % path )
converted = path_convert( path, pathLibFrom, pathLibTo)
print(' converted %s' % converted )
print(' reversed %s' % path_convert( path, pathLibTo, pathLibFrom) )
test_path_convert( r'C:\Users\gyb\Desktop\Circular Saw Jig\Side support V1.00.FCStd', ntpath, os.path )
Because I deactivated my icon, you will get a button in the toolbar if you add one line and a comma-separator to the file InitGui.py (i marked the changes within the code).
Please find it here:
Code: Select all
import assembly2lib #QtCore.QResource.registerResource happens in assembly2lib
class Assembly2Workbench (Workbench):
MenuText = 'Assembly 2'
def Initialize(self):
import axialConstraint, assembly2solver, importPart, planeConstraint, circularEdgeConstraint, muxAssembly, angleConstraint, partsList, degreesOfFreedomAnimation, \
sphericalSurfaceConstraint, checkAssembly, boltMultipleCircularEdges, animate_constraint, undo
commandslist = [
'importPart',
'updateImportedPartsCommand',
'assembly2_movePart',
'addCircularEdgeConstraint',
'addPlaneConstraint',
'addAxialConstraint',
'addAngleConstraint',
'addSphericalSurfaceConstraint',
'a2_UndoConstraint',
'degreesOfFreedomAnimation',
'assembly2SolveConstraints',
'muxAssembly',
'muxAssemblyRefresh',
'addPartsList',
'assembly2_checkAssembly', #================== add comma-separator here ======================
'a3_ViewConnectionsCommand' #===============> this line is to bee added ==========================
]
self.appendToolbar('Assembly 2', commandslist)
shortcut_commandslist = [
'flipLastConstraintsDirection',
'lockLastConstraintsRotation',
'boltMultipleCircularEdges',
]
self.appendToolbar('Assembly 2 shortcuts', shortcut_commandslist )
self.treecmdList = ['importPart', 'updateImportedPartsCommand']
FreeCADGui.addIconPath( ':/assembly2/icons' )
FreeCADGui.addPreferencePage( ':/assembly2/ui/assembly2_prefs.ui','Assembly2' )
self.appendMenu('Assembly 2', commandslist)
def Activated(self):
from assembly2lib import FreeCAD, updateOldStyleConstraintProperties
import os, undo
doc = FreeCAD.activeDocument()
if hasattr(doc, 'Objects'):
updateOldStyleConstraintProperties(doc)
__dir2__ = os.path.dirname(undo.__file__)
GuiPath = os.path.expanduser ("~") # os.path.join( __dir2__, 'Gui' )
constraintFile = os.path.join( GuiPath , 'constraintFile.txt')
if os.path.exists(constraintFile):
os.remove(constraintFile)
def ContextMenu(self, recipient):
selection = [s for s in FreeCADGui.Selection.getSelection() if s.Document == FreeCAD.ActiveDocument ]
if len(selection) == 1:
obj = selection[0]
if hasattr(obj,'Content'):
if 'ConstraintInfo' in obj.Content or 'ConstraintNfo' in obj.Content:
redefineCmd = {
'plane':'redefinePlaneConstraint',
'angle_between_planes':'redefineAngleConstraint',
'axial': 'redefineAxialConstraint',
'circularEdge' : 'redefineCircularEdgeConstraint',
'sphericalSurface' : 'redefineSphericalSurfaceConstraint'
}[ obj.Type ]
self.appendContextMenu( "Assembly2", [
'assemly2_animate_constraint',
redefineCmd,
'selectConstraintObjects',
'selectConstraintElements'])
if 'sourceFile' in obj.Content:
self.appendContextMenu(
"Assembly2",
[ 'assembly2_movePart',
'assembly2_duplicatePart',
'assembly2_editImportedPart',
'assembly2_forkImportedPart',
'assembly2_deletePartsConstraints',
'assembly2_randomColorAll']
)
Icon = ':/assembly2/icons/workBenchIcon.svg'
Gui.addWorkbench(Assembly2Workbench())
I see the new button in the toolbar of assembly2:
I select a constraint within my assembly...
and hit the new button:
Everything becomes transparently and you can have a look at the constraint. The two involved parts are hightlighted in the tree view...
Quit the dialog and everything looks like before.
Hope this helps (and urgently waiting for the next generation assembly....),
regards,
Klaus
P.S: Unfortunately you have to hit an extra button
KBWBE
https://github.com/kbwbe/A2plus
latest release: v0.4.56, installable via FreeCAD's addon manager
Tutorial: gripper assembly https://www.youtube.com/watch?v=QMxcQ5tssWk
Documentation: https://www.freecadweb.org/wiki/A2plus_Workbench
https://github.com/kbwbe/A2plus
latest release: v0.4.56, installable via FreeCAD's addon manager
Tutorial: gripper assembly https://www.youtube.com/watch?v=QMxcQ5tssWk
Documentation: https://www.freecadweb.org/wiki/A2plus_Workbench
Re: Anyway to highlight the assembly constraints?
Hi,
there is already a way to highlight A2 relations
https://forum.freecadweb.org/viewtopic. ... 40#p150135
there is already a way to highlight A2 relations
https://forum.freecadweb.org/viewtopic. ... 40#p150135
Re: Anyway to highlight the assembly constraints?
Sorry,
because I am still working with my on fork, i did not recognize this. Thanks for advice
regards,
Klaus
because I am still working with my on fork, i did not recognize this. Thanks for advice
regards,
Klaus
KBWBE
https://github.com/kbwbe/A2plus
latest release: v0.4.56, installable via FreeCAD's addon manager
Tutorial: gripper assembly https://www.youtube.com/watch?v=QMxcQ5tssWk
Documentation: https://www.freecadweb.org/wiki/A2plus_Workbench
https://github.com/kbwbe/A2plus
latest release: v0.4.56, installable via FreeCAD's addon manager
Tutorial: gripper assembly https://www.youtube.com/watch?v=QMxcQ5tssWk
Documentation: https://www.freecadweb.org/wiki/A2plus_Workbench
Re: Anyway to highlight the assembly constraints?
Not to be sorry at all,
your code is useful and can be used in other user cases
your code is useful and can be used in other user cases
Re: Anyway to highlight the assembly constraints?
Hi kbwbe,
It works. Which is great. But it could be a bit more user-friendly, so here are 2 top tips from Koemi for free (if you like it or not...)
Top tip 1
After clicking 'show constraint' the messagebox 'Close Connection ViewMode' appears. Exactly in the middle of the image, THE place where you want to see the constraints you are looking for and not a message box which you have to move away from the center of the screen. If I just hit the escape button everything is back in order, so I would say: get rid of the messagebox .
Top tip 2
After clicking 'show constraint' the image is locked in position. It would be nice if you still have the possibility to move, rotate and zoom the image which makes it possible to see the constraints which you are looking for. I think it is the messagebox which freezes the screen?
No worries. I will definately use this extra button. These are just friendly tips. Maybe it is a small change in the code. I am not a py-programmer so I am not able to adapt it.
It works. Which is great. But it could be a bit more user-friendly, so here are 2 top tips from Koemi for free (if you like it or not...)
Top tip 1
After clicking 'show constraint' the messagebox 'Close Connection ViewMode' appears. Exactly in the middle of the image, THE place where you want to see the constraints you are looking for and not a message box which you have to move away from the center of the screen. If I just hit the escape button everything is back in order, so I would say: get rid of the messagebox .
Top tip 2
After clicking 'show constraint' the image is locked in position. It would be nice if you still have the possibility to move, rotate and zoom the image which makes it possible to see the constraints which you are looking for. I think it is the messagebox which freezes the screen?
No worries. I will definately use this extra button. These are just friendly tips. Maybe it is a small change in the code. I am not a py-programmer so I am not able to adapt it.
Re: Anyway to highlight the assembly constraints?
Hi kbwbe,
still working with the "Show constraint"-button. I am glad to have it, but I noticed a small bug, which is maybe easy to change in the code
Sometimes Assembly2 fundles around with constraints which are present in the combo view, but actually don't exist. I have no idea why these things happen... Assembly2 is buggy (and for some reason getting slow as hell when assemblies grow ), but I am very glad this workbench exists of course
Anyway, if I click on one of these constraints and after that I click your "Show constraint"-button, the assembly becomes transparent and stays that way. Unfortunaly there is no escape from that, so I need to un-transparent all parts in the assembly manually...
Could this be a small change maybe?
still working with the "Show constraint"-button. I am glad to have it, but I noticed a small bug, which is maybe easy to change in the code
Sometimes Assembly2 fundles around with constraints which are present in the combo view, but actually don't exist. I have no idea why these things happen... Assembly2 is buggy (and for some reason getting slow as hell when assemblies grow ), but I am very glad this workbench exists of course
Anyway, if I click on one of these constraints and after that I click your "Show constraint"-button, the assembly becomes transparent and stays that way. Unfortunaly there is no escape from that, so I need to un-transparent all parts in the assembly manually...
Could this be a small change maybe?