Messing around with the topo-naming issue

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
freedman
Veteran
Posts: 3465
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Messing around with the topo-naming issue

Post by freedman »

Anyone have any input on how to swap a sketch in a macro, something like this: I create sketch_1 and then make a duplicate sketch_2 with a small modification, then pad sketch_1. Now I would like to swap sketch_2 into sketch_1 and recompute to get the new pad, is that possible?? I would like to swap the sketch as an object, not just parts of it.
Can I just change the name in the linklist?

Thanks
mario52
Veteran
Posts: 4690
Joined: Wed May 16, 2012 2:13 pm

Re: Messing around with the topo-naming issue

Post by mario52 »

hi

use the Macro Record the complete code of all operations is saved in one file


Std_Macro_Menu

Image

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
kisolre
Veteran
Posts: 4166
Joined: Wed Nov 21, 2018 1:13 pm

Re: Messing around with the topo-naming issue

Post by kisolre »

I created a sketch, padded, created a second sketch, replaced the pad.Profile to sketch 2. In python console replacement looked like this:

Code: Select all

FreeCAD.getDocument('Unnamed').getObject('Pad').Profile = FreeCAD.getDocument('Unnamed').getObject('Sketch001')
freedman
Veteran
Posts: 3465
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Messing around with the topo-naming issue

Post by freedman »

kisolre, thank you, that worked great.
freedman
Veteran
Posts: 3465
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Messing around with the topo-naming issue

Post by freedman »

If I have a sketch (attached to a face) and the face gets renumbered the sketches placement will change. I can put the sketch back where it was (placement wise) and the next logical step is to find the new face number at that placement. That's my question; If I have a sketch sitting on a face ( not attached) what do I need to do to get the face number I'm sitting on?
I can march the Tip thru the features (to get face numbers) but I don't know how to compare an unattached sketch placement with a face placement.
Thanks
freedman
Veteran
Posts: 3465
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Messing around with the topo-naming issue

Post by freedman »

If I have a sketch (attached to a face) and the face gets renumbered the sketches placement will change. I can put the sketch back where it was (placement wise) and the next logical step is to find the new face number at that placement.
Thought I would answer my own question (with an approach) in case folks are interested.

My plan is to add additional properties for sketches and store a backup of their current placement which is updated when created and properly moved.
When I scan through the sketches if I see a difference between the backup placement and the current placement then I know a topo-error moved my sketch to a different place, so now I need to figure out where the sketch should be. Computers are good at repetitive tasks so I will loop thru the faces and attach the sketch to every face (one at a time) of the feature/features, recompute and look at the placement numbers, one of the placements should be correct or close. Now that's what I call a work-around. :lol:

If I don't find a perfect match then I start to solve for it and surely attach the sketch to a face. But that's another chapter in the story... :)

This might be fun to watch if I slow it down.
Last edited by freedman on Fri Dec 18, 2020 6:29 pm, edited 1 time in total.
chrisb
Veteran
Posts: 54168
Joined: Tue Mar 17, 2015 9:14 am

Re: Messing around with the topo-naming issue

Post by chrisb »

Two points to think about: 1) It would be interesting to see how you check for a sketch being "close" to its previous position.
2) Imagine a cube, with sketches attached to each of the six sides. Now you move the cube quite a bit and you turn it. ZThen none of the sketches will be at its previous position, nor will it be close.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
freedman
Veteran
Posts: 3465
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Messing around with the topo-naming issue

Post by freedman »

chrisb, 1) It would be interesting to see how you check for a sketch being "close" to its previous position.
That I think is "marching". I offset the sketch in the Z-direction, recompute and look for an error. This could fix a multiple solid error. Once the error is corrected the backup placement will be updated. This is certainly solver territory.
chrisb, 2) Imagine a cube, with sketches attached to each of the six sides. Now you move the cube quite a bit and you turn it.
2) My thinking/writing was wrong about error handling. I will watch for a FreeCAD (topo-error or multiple solid) error and then try to relocate sketches. So normally FreeCAD would update sketch placements if a cube was moved.

I think the way this works; my macro looks for a successful recompute, it will then update all the sketch backup placements.

I'm now writing a macro that can create sketch placement backups for all sketches and swap placements for a recompute. This should help do some testing.
Thanks
chrisb
Veteran
Posts: 54168
Joined: Tue Mar 17, 2015 9:14 am

Re: Messing around with the topo-naming issue

Post by chrisb »

Curious about it. This would be much easier to integrate in master than realthunder's branch. Please note tht toponaming errors often occur without a formal FreeCAD error.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
freedman
Veteran
Posts: 3465
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Messing around with the topo-naming issue

Post by freedman »

chrisb, Please note that toponaming errors often occur without a formal FreeCAD error.
That is a problem, hopefully the logic behind every change in placement can be resolved.

Error or issue handling reporting from FreeCAD is in a poor state. I have yet to read a post where anyone has found a solid way to get errors. I do know the "status" can be checked but it is not very informative. Software work on error reporting might be key to making this work.

Some thoughts on things to look for when a recompute occurs:
1) The total number of faces in a model has changed.
2) The number of sketch elements (per sketch) changed, I believe every element is a face.
3) Sketch placement changed.
4) FreeCAD detects an error.
Post Reply