"Reframe On" problem

Grzegorz Olesinski

"Reframe On" problem

Hi

I need to use "reframe on" or - better - "reframe on work object" method through VBA. I've tried CATIA.StartCommand "Reframe On Work Object" (and "Reframe On" too), but it doesn't work. It gives no errors, but nothing happens. I couldn't find any API function to do that too. Any ideas?

Steven Kwok

RE: "Reframe On" problem
(in response to Grzegorz Olesinski)
The following code will do a reframe on your active window, but basically all it is at the moment is CATIA.StartCommand("Fit All In") in long form. Maybe you can morph it into something else?

==========================

Dim Window1 As Window
Set Window1 = CATIA.ActiveWindow

Dim Viewer1 As Viewer
Set Viewer1 = Window1.Viewers.Item(1)

Viewer1.Reframe

========================

Also note that CATIA does not reframe well on features, because it tends to grab the full body. It reframes well on sketches, geometric items, and entire parts. I could not get it to reframe on a selection unfortunately. Maybe someone else knows how?

Cliff Johnson, Cliff

RE: "Reframe On" problem
(in response to Grzegorz Olesinski)

Select the item first then StartCommand("Reframe On" ) will work.

 

Sub CatMain()
    Dim sel As Selection
    Set sel = CATIA.ActiveDocument.Selection
    Dim myPlane as Plane

    Set myPlane = CATIA.ActiveDocument.Part.HybridBodies.Item("Geometrical Set.1" ).HybridShapes.Item("Plane.3" )
    sel.clear
    sel.add myPlane
    CATIA.StartCommand ("Reframe On" )
End Sub

Steven Kwok

RE: "Reframe On" problem
(in response to Grzegorz Olesinski)
Interesting Cliff. I tried an interactive selection and it didn't want to take the generic selection. I should have known. It looks like you have to add the explicit selection before performing the reframe command.

Grzegorz Olesinski

RE: "Reframe On" problem
(in response to Grzegorz Olesinski)
Cliff
I've tried that. I've tried make the object "in work object", to use "Reframe On Work Object" too and nothing works. I thought it is because I use forms, but I've writen simple code in catscript and result is the same

Cliff Johnson, Cliff

RE: "Reframe On" problem
(in response to Grzegorz Olesinski)
Does the code I posted work for you? (Make a Plane.3 in Geometrical Set.1 first)

It does for me. It works with solid bodies too:

Dim myBody as Body
Set myBody = catia.activedocument.part.bodies.item("PartBody" )

...

sel.add myBody

...

Using a form shouldn't matter. Show us your catscript.

Grzegorz Olesinski

RE: "Reframe On" problem
(in response to Grzegorz Olesinski)
Sub CATMain()

Dim part1 As Part
Set part1 = CATIA.ActiveDocument.Part

Dim sel1 As Selection
Set sel1 = CATIA.ActiveDocument.Selection
sel1.Clear

sel1.Add part1.HybridBodies.Item(1).HybridShapes.Item(1)

CATIA.StartCommand ("Reframe On")

End Sub


Selection works, but still nothing happens

Cliff Johnson, Cliff

RE: "Reframe On" problem
(in response to Grzegorz Olesinski)
That works for me just fine.

Steven Kwok

RE: "Reframe On" problem
(in response to Grzegorz Olesinski)
Alright, now comes for the time when we list what versions/SP of CATIA we are using.

CATIA R16 SP0 = FAIL
CATIA R17 SP0 = FAIL
CATIA R18 SP0 = SUCCESS

That's the answer...

Grzegorz Olesinski

RE: "Reframe On" problem
(in response to Grzegorz Olesinski)
That makes sens. I use R16 SP5 and doesn't work too. I've found a workarround - I hide all elements but one I want to "reframe on" and I use reframe method on viewer object. Then I bring all elements to show. Maybe not to sophisticated, but works.

Kevin Arnold

VBA Select then "Reframe On" problem
(in response to Grzegorz Olesinski)

I'm on V5R28 and I can select the object with VBA, it turns orange in the tree, but not graphically, so when I do the Catia.StartCommand "Reframe On", nothing happens. if I click the object with my mouse, both tree and object turn orange and Reframe On works. We need mouse free Object Selection and Reframe On. Need a little help here.

Josh Bender

RE: VBA Select then "Reframe On" problem
(in response to Kevin Arnold)

Can you provide a bit of your code? 

 Are you working in a product? Or in a part?

Kevin Arnold

RE: VBA Select then "Reframe On" problem
(in response to Josh Bender)

Working in a Product.

 My goal is to Zoom In on the plane

 

'======================================
mySelection.Clear()
mySelection.Add(myPart)
AppActivate("CATIA V5 R28 SP05")
SendKeys.Send("c:FrmActivate" & Chr(13))
mySelection.Add(myHB)
mySelection.Add(myPlane)
'myPart.InWorkObject = myHB

'CATIA.StartCommand("Activate")
CATIA.StartCommand("Reframe On")
'======================================

Edited By:
Kevin Arnold[Organization Members] @ Aug 09, 2021 - 08:40 AM (America/Eastern)

Josh Bender

RE: VBA Select then "Reframe On" problem
(in response to Kevin Arnold)

Kevin,

I think your problem stems from having multiple objects selected when running "Reframe On". By the time you call reframe, you have 3 objects selected:

'======================================
mySelection.Clear()
mySelection.Add(myPart) <------------------- Object #1 -
AppActivate("CATIA V5 R28 SP05")
SendKeys.Send("c:FrmActivate" & Chr(13))
mySelection.Add(myHB) <------------------- Object #2 - Geometric set?
mySelection.Add(myPlane) <------------------ Object #3 - The plane
'myPart.InWorkObject = myHB
'CATIA.StartCommand("Activate")
CATIA.StartCommand("Reframe On")
'======================================

 

This would cause the reframe to take into account every aspect of the part model (zoomed too far out)

If you specifically want to reframe on the plane only, I think this should solve your problem. Although this zooms all the way in. Maybe moving the clear object before the geometric set will provide the desired effect?

'======================================
mySelection.Clear()
mySelection.Add(myPart)
AppActivate("CATIA V5 R28 SP05")
SendKeys.Send("c:FrmActivate" & Chr(13))
mySelection.Add(myHB)
mySelection.Clear()

mySelection.Add(myPlane)
'myPart.InWorkObject = myHB
'CATIA.StartCommand("Activate")
CATIA.StartCommand("Reframe On")
'=====================================

Kevin Arnold

RE: VBA Select then "Reframe On" problem
(in response to Josh Bender)

No that doesn't work, obviously I've tried every variation with these objects and doing the

selection does not make them the selected object on the graphical screen, only in the tree.

in order for "Reframe On" to work the object needs to be selected and orange in both the tree and the graphics screen.

Little Cthulhu

RE: VBA Select then "Reframe On" problem
(in response to Kevin Arnold)

Try:

CATIA.HSOSynchronized = True

In reality to properly add objects to selection in a product you must address them in product's context.

How do you retrieve your plane in the first place? Can you post a full code?

Kevin Arnold

RE: VBA Select then "Reframe On" problem
(in response to Little Cthulhu)

I create myPlane

myPlane = myHBShapeFactory.AddNewPlaneOffset(myOrigElmts.PlaneXY, 0, False)

mySelection.Clear()
mySelection.Add(myPlane)

it does not matter where myPlane is at in the Product or Part, it will always select it,

it selects it perfectly, it will "Center Graph" it just will not "Reframe On"

No matter what I add as the selection, a part, a body, a point, it will not "Reframe On"

with VBA code, it will only Reframe On if the item was selected with a mouse click.

 

Little Cthulhu

RE: VBA Select then "Reframe On" problem
(in response to Kevin Arnold)

How do you add myPlane to your part specification tree?

How do you retrieve mySelection?

Have you tried using command alias: CATIA.StartCommand "CATAfrReframeOnHSOHdr"

Kevin Arnold

RE: VBA Select then "Reframe On" problem
(in response to Little Cthulhu)

myOrigElmts = myPart.OriginElements
myPlane = myHBShapeFactory.AddNewPlaneOffset(myOrigElmts.PlaneXY, 0, False)
myPlane.Name = "TopBottom_Plane"
myHBBody.AppendHybridShape(myPlane)
myPart.Update()

mySelection = CATIA.ActiveDocument.Selection
mySelection.Clear()
mySelection.Add(myPlane)

CATIA.StartCommand("Center Graph") 'This Works, this brings myPlane to the center on the Tree
CATIA.StartCommand("Reframe On")  'This Does Not Work, myPlane is still way over there in right field
CATIA.StartCommand("CATAfrReframeOnHSOHdr")  'This Does Not Work

 

Attachments

  • Select_ReframeOn.mp4 (1131k)

Little Cthulhu

RE: VBA Select then "Reframe On" problem
(in response to Kevin Arnold)

Thanks for the video.

Remove "FrmActivate" from your code completely. It's officially not supported and known to cause problems.

Code below works for me:

Sub CATMain()
Dim doc: Set doc = CATIA.Documents.Add("Product")
Dim prt: Set prt = doc.Product.products.AddNewComponent("Part", "SelectionTest" + CStr(Timer())).ReferenceProduct.Parent.part
Dim hsf: Set hsf = prt.HybridShapeFactory
Dim pln: Set pln = hsf.AddNewPlaneOffset(prt.OriginElements.PlaneXY, 500, True)
prt.mainBody.InsertHybridShape pln
prt.Update
doc.Selection.Add pln
CATIA.StartCommand "CATCafCenterGraphHdr"
CATIA.StartCommand "CATAfrReframeOnHSOHdr"
End Sub

Kevin Arnold

RE: VBA Select then "Reframe On" problem
(in response to Little Cthulhu)

Your right, it works if I'm in a .CATProduct or a .CATPart but not if I'm in a .CATProcess

Little Cthulhu

RE: VBA Select then "Reframe On" problem
(in response to Kevin Arnold)

Glad we've managed to find out that .CATProcess document has to be active and have not waisted our time with irrelevant scenarios.

I'll see if I can find some more time to look into it.

Edited By:
Little Cthulhu[Subscriber Members] @ Aug 15, 2021 - 01:36 PM (Europe/Moscow)
Little Cthulhu[Subscriber Members] @ Aug 15, 2021 - 01:37 PM (Europe/Moscow)

Little Cthulhu

RE: VBA Select then "Reframe On" problem
(in response to Little Cthulhu)

Code above works fine for a part inserted into ProductList node inside .CATProcess document.

I need a sample .CATProcess and a script that doesn't work on your side.

Kevin Arnold

RE: VBA Select then "Reframe On" problem
(in response to Little Cthulhu)

I have found out that inside a .CATProcess if I use :

mySelection.Clear()
mySelection.Add(myPlane)
CATIA.StartCommand("CATAfrReframeOnHSOHdr")

even tho myPlane is selected in the tree, it is not selected on the graphical screen so "Reframe On" does not work.

BUT if I use:

mySelection.Clear()
mySelection.Search("'Part Design'.'Plane',all")
mySelection.Search("Name=TopBottom_Plane,sel")
CATIA.StartCommand("CATAfrReframeOnHSOHdr")

myPlane is selected in the tree and on the graphical screen thus the "Reframe On" does work.