Behaviour of Object.Tip with PartDesign LinearPattern

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
vectronic
Posts: 52
Joined: Sun Feb 18, 2018 9:44 pm

Behaviour of Object.Tip with PartDesign LinearPattern

Post by vectronic »

Hello,

I've been working on a python macro to produce the model in the following screenshot:

actual.png
actual.png (749.86 KiB) Viewed 1253 times

I have been relying on the following to set the "last" PartDesign item in the body as the visible item in the GUI:

Code: Select all

brickObject.Tip.ViewObject.Visibility = True

This has worked well until now, when I have started to use LinearPattern.

Tip seems to ignore the LinearPatterns and considers the Pocket as the Tip of the brick object. You can see this in the screenshot above where I have tried to achieve what I want in the Python console with:

Code: Select all

Gui.ActiveDocument.brick.Object.Tip.ViewObject.Visibility = True

What I would like this to do is set the last LinearPattern visible. You can see the desired outcome which I have achieved manually in the the following screenshot:

desired.png
desired.png (840.18 KiB) Viewed 1253 times

Is this Tip behaviour expected or a bug?


If expected, how could I access the last item in the brick object?


NOTE: I could reference it via the name e.g.

Code: Select all

Gui.ActiveDocument.front_pin_linear_pattern.Visibility = True


However I am wanting to do this in a generic way from a separate module of code which does not know how many items are in the brick body or the names of these items. So I have been relying on the fact that Tip accesses the "last" item in the brick body.

Example model file here: https://f001.backblazeb2.com/file/vectr ... mple.FCStd

Version details:

OS: macOS 10.16
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.20.24562 (Git)
Build type: Release
Branch: master
Hash: 8277b3f9e9b66092a58625f3a2a87a0d60dcc580
Python version: 3.8.8
Qt version: 5.12.5
Coin version: 4.0.0
OCC version: 7.4.0
Locale: English/United Kingdom (en_GB)
kisolre
Veteran
Posts: 4159
Joined: Wed Nov 21, 2018 1:13 pm

Re: Behaviour of Object.Tip with PartDesign LinearPattern

Post by kisolre »

Tip is not necessarily the last object in the tree. Otherwise there will be no point of its existence. You could check how are you creating those linear patterns and why the Tip does not move when they are created.
vectronic
Posts: 52
Joined: Sun Feb 18, 2018 9:44 pm

Re: Behaviour of Object.Tip with PartDesign LinearPattern

Post by vectronic »

@kisolre

Thanks for your response.

"Tip is not necessarily the last object in the tree. Otherwise there will be no point of its existence."

=> If Tip does not point to the last feature in the body, what does Tip represent?

=> Your answer makes me think I need to look into whether I can access all the features contained in the body and then use the last one - assuming that there is an ordered list of these features and the last feature in the list is the one I am after.

"You could check how are you creating those linear patterns and why the Tip does not move when they are created."

=> As per my understanding I have created the linear patterns correctly. I have used similar code for all other features in the model:

Code: Select all

...
	features = [pin_revolution, pin_pipe, pin_notch_pocket] # where pin_revolution, pin_pipe and pin_notch_pocket are features already created in the body

        pin_linear_pattern = self.brick.newObject("PartDesign::LinearPattern", label + "_pin_linear_pattern")
        pin_linear_pattern.Originals = features
        pin_linear_pattern.Direction = (features[0].Profile[0], ['N_Axis'])
        pin_linear_pattern.Length = 8
        pin_linear_pattern.Occurrences = 2

        self.doc.recompute()
...
=> I do not know why the Tip does not move when they are created. This is why I am asking whether the Tip should move and therefore, possibly, if this is a bug?

Thanks again,
Nick
kisolre
Veteran
Posts: 4159
Joined: Wed Nov 21, 2018 1:13 pm

Re: Behaviour of Object.Tip with PartDesign LinearPattern

Post by kisolre »

vectronic wrote: Thu Aug 26, 2021 3:14 pm what does Tip represent?
PartDesign_MoveTip
Could you post the complete script for examination? Somebody more knowledgeable might have an idea. It looks ok to me.
kisolre
Veteran
Posts: 4159
Joined: Wed Nov 21, 2018 1:13 pm

Re: Behaviour of Object.Tip with PartDesign LinearPattern

Post by kisolre »

And an idea for simple construction - multitransform with 2 mirrors and polar pattern:
Attachments
Connector.FCStd
(24.94 KiB) Downloaded 29 times
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Behaviour of Object.Tip with PartDesign LinearPattern

Post by TheMarkster »

Perhaps you can set the tip manually after creating each feature/pattern.

body.setTip(pin_linear_pattern)

Edit: make that body.Tip = pin_linear_pattern
vectronic
Posts: 52
Joined: Sun Feb 18, 2018 9:44 pm

Re: Behaviour of Object.Tip with PartDesign LinearPattern

Post by vectronic »

Thanks to the response from @kisolre I had a look at the test code for "PartDesign::LinearPattern" here:

https://github.com/FreeCAD/FreeCAD/blob ... #L122-L137

It was slightly different to the code I was using i.e:

Code: Select all

pin_linear_pattern = self.doc.addObject("PartDesign::LinearPattern", label + "_pin_linear_pattern")
self.brick.addObject(pin_linear_pattern)
instead of:

Code: Select all

pin_linear_pattern = self.brick.newObject("PartDesign::LinearPattern", label + "_pin_linear_pattern")
With this change, the tip was indeed updated! :)

This also worked with another issue I had with the Tip not updating when using "PartDesign::Mirrored".

So thanks very much for the help!

One follow on question (I'm still a relative newbie to FreeCAD):

I was trying to work out where and how I decided to use "newObject()" originally and not "addObject()". I have been unable to find a definitive Python API guide location (I understand it might not all be documented due to the effort required). But what is currently considered the best place to look for Python API information on the web? What is the current consensus on where efforts should be placed to expand the documentation.
Post Reply