-
-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to read a virtual constraint's "distance" property? #52
Comments
This possible, and actually not that difficult to do. I am just not sure whether assembly WB is the right place to provide this feature. Let me think about it. |
Thinking again, currently I can not imagine any useful cases that would require using values other than
This approach also seems
It's almost done, but the problem is that the coordinates of points does not change when I move the bound part:
|
Oh, wait, wait, it's |
No luck yet. I expect the following code to output App.ActiveDocument.Point001.Placement.Base.x - App.ActiveDocument.Point.Placement.Base.x in this model because Manipulator WB measures |
Instead of using DraftPoint, you should use a DraftLine here. Simply constraint the two end point of the line to those two cubes. And you can read out the |
DraftLine approach (limited success): box-with-draft-line.fcstd.remove-extension.zip While this seem to work as expected, we can not move the red cube in the other directions because the DraftLine should be and is also parallel to outer box edge. Moreover, DraftLine creates undesired interference with movement of connected objects: |
You should completely fix two box with constrains first (hint: if you don't want the box to rotate, use LockAngle in PlaneAlignment), then add the draft line. You can use constraints other than point coincidence, for example, to measure point to plane distance with perpendicular and point in plane. |
I will only continue this conversation if you have your word that you won't find me and shoot me in the head. |
Wait, what? |
I think I asked too many things already :) |
It's nice to have an active tester. Besides, the thing you are trying to do is really at the frontier in the world of FreeCAD. I think nobody yet has a clear idea of what's the best workflow in FC. |
Okay, I assume I got your word then :)
That would be an obvious resolution, but it seems it's not that practical because we have to explicitly declare all constraints for a design, which removes the freedom of "okay, you, box, stay where I put you".
Yes, I thought about that too, but what if the objects will be rotated? Or objects have no plain faces? All these experiments were for clarifying if "Asm3 is the right place to ask this or not" (from the point of view of myself) and led me to that point: This feature (which I want to call it "Assembly [Based] Dimensions") should be used in the following way (in the end):
This operation should be that easy. Although a separate caliper tool and snapping to center are fancy features, I guess it would be both practical and doable by that "virtual constraints". |
The virtual constraint proposal will face the exact same problems above. As long as the part's movement is legal with the given constraints, it is perfectly normal for the next auto solve to change the part's placement and ruin your measurement. I am investigating other possibilities, such as supporting shape distance calculation directly in expression, which may or may not be possible. BTW, it is easy to snap a draft point/line on the center of any face. Simply use the PointCoincident constraint on that face and point, PointCoincident will use the center of the face as a point. |
With this commit, it is now possible to get distance and many more information directly from expression. If the parts you want to measure are inside the same assembly, then the following expression measure two vertex from two boxes,
There is also distanceToLine/Plane(), etc. Anything exposed by Python through the property can be used in the expression. If the Box are inside different assembly, the recommended way of doing it is to create |
A Mini TutorialAs an example, I created two elements, labeled front = lambda: App.ActiveDocument.getObjectsByLabel('front')[0].Shape
back = lambda: App.ActiveDocument.getObjectsByLabel('back')[0].Shape GoalMeasure the distance between them with Get the distance quicklyfront().Vertexes[0].Point.distanceToPoint(back().Vertexes[0].Point)
# => 6.5 (which seems what we wanted)
front().Vertexes[0].Point.distanceToPoint(back().Vertexes[1].Point)
# => 17.45377259416224 (upps!)
# How do we know which vertices will give us the correct measurement? Correct WayIt's obvious that we should measure the distance between a random point from one plane to the other plane itself (PointToPlane): def get_plane(p1, p2, p3):
edge1 = p1 - p2
edge2 = p1 - p3
normal = edge1.cross(edge2)
return (p1, normal)
def get_element_plane(shape):
v = shape.Vertexes
return get_plane(v[0].Point, v[1].Point, v[2].Point)
x1 = front().Vertexes[0].Point
x2 = get_element_plane(back())
dist = x1.distanceToPlane(*x2)
# => 6.5 (exactly what we expected) ConclusionAs we used two MacroHere is the macro that calculates the distance declared in a Spreadsheet: https://github.com/ceremcem/assembly-dimensions Usage
|
I have enhanced spreadsheet such that it can perform some complex tasks of a macro. Here is a one liner that you can directly type into spreadsheet
Or better, use labels,
Or even better, break it into cells
You see how it can replace macros? I think I'll further enhance the spreadsheet cell to accept parameters. Then it can really be a macro. |
Much easier to use and provides some more advanced usage scenarios than using with macro. |
One question: How can we perform mathematical operations with the output of Problem is that currently it seems to fail |
Times 1mm |
I have created an |
That shouldn't be possible. Every |
Aha! Yes, I just found too: the previous enhancement (#70) requires it to be possible to duplicate labels, so >>> App.ActiveDocument.getObjectsByLabel('ref-support-back')
[<App::FeaturePython object>, <Part::PartFeature>, <App::FeaturePython object>] |
Question: Can we use a constraint for the purpose? It would be a lot easier to declare/maintain a dynamic distance by using constraints (or, maybe, a virtual constraint?). |
I sure can. Be careful, though, distance measured this way cannot be used by any object inside the same assembly or any of its child assembly. |
Same reason of #98 (comment), right? I think that might be somehow possible (because we do this in real life) but I need to think about this calmly. Until that time, it's okay to avoid using such "cyclic dependency" cases. |
Taking the request one step further: It would be great to have a
|
What do you mean by Caliper tool? A button on the toolbar? |
Yep, sure. |
I'm not sure if you released the tools or not, but current version includes the tools, thank you. However, they give the following exception:
|
Please sync asm3 repo |
Still having errors in an empty document (same exception) |
oops, my mistake. Please try again |
Exception is gone, it's okay. How could we use a
|
Upps, it seems it's like:
(don't use dashed labels when you are going to refer it within a spreadsheet) |
PropertyExpressionEngine::execute() can be divided to two steps, to compute non-output properties before object execute(), and then compute only output propertyies afterwards. Fixes realthunder/FreeCAD_assembly3#52
Label2 is my experiment of supporting user defined descriptional information of an object. It is shown in the tree view as a second |
Wow! Nice! That was something I was thinking about. My actual target was related with SheetMetal WB, where if we could embed an information into a line - like "95 degree, bend towards XXX direction" - so that the TechDraw WB can use that information to generate additional markings. Nice feature! |
If we could create a virtual constraint and read its data as if any other object within the Spreadsheet, it would be possible to create dynamically calculated dimensions: https://forum.freecadweb.org/viewtopic.php?f=3&t=30676
Is it possible to read - i.e. -
distance
property of a disable constraint:The text was updated successfully, but these errors were encountered: