Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro chokes on Parameters.Item("X Axis")

Status
Not open for further replies.

mvangild

Automotive
Dec 5, 2005
5
OK, got another question. In R12.4.15, I opened an existing IGES file and immediately started recording a macro to create a single pad from a single surface in the X direction. I closed the file without saving changes, re-opened the same IGES file, and tried to run the macro. It failed, giving me the error "The method Item failed" in reference to the line "Set hybridShapeLineExplicit1 = parameters2.Item("X Axis")" ( a more complete version of this code follows below). The macro is in VBScript. Do I need to have the macro create a line in the X direction? Or is there something else that needs done? When macros won't even work when running the macro from the exact same point that you started recording from, it makes it a bit difficult to figure out what's going on. As promised, here's the relevant code that CATIA recorded.

Sub CATMain()
...
Set reference1 = part1.CreateReferenceFromName("")

Set pad1 = shapeFactory1.AddNewPadFromRef(reference1,20.00)

Set parameters1 = part1.Parameters

Set hybridShapeSurfaceExplicit1 = parameters1.Item("surfname")

Set reference2 = part1.CreateReferenceFromObject(hybridShapeSurfaceExplicit1)

pad1.SetProfileElement reference2

Set parameters2 = part1.Parameters

Set hybridShapeLineExplicity1 = parameters2.Item("X Axis")
' ^^ this is where the macro fails

Set reference3 = part1.CreateReferenceFromObject(hybridShapeLineExplicit1)

...

End Sub

So, why does it choke on the reference to the X Axis? Thanks for the help in advance.
 
Replies continue below

Recommended for you

Ok, never mind, I figured that one out. Here's another one:
I am calling out a draft in a macro, and I am trying to automate it. When the face is picked and I display it in a macro, it comes up as:

Set reference3 = part1.CreateReferenceFromBRepName("Rsur:(Face:(Brp:(Pad.1;0:(Brp:
(GSMBiDim.1;2)));None:();Cf9());WithTemporaryBody;WithoutBuildError;
WithSelectingFeatureSupport)",pad1)

Since this line is in a loop which can reference other pads other than Pad.1, I'm pretty sure this line needs to change (especially with the references to Pad.1 and GSMBiDim.1). The plan is to : take surface, build pad, draft 4 sides of same pad, add part body, index to next surface, repeat until finished with all surfaces. I attempted to use a variable called counter and use it with the syntax Pad.counter, which failed (as you can tell, VBScript isn't exactly my strong suit). So the question is: how do I get this line to reference the faces of the most recently built pad? Thanks for the help in advance.
 
I assume you have grouped all surfaces in the same set.
All the HybridShapes (surfaces, intersects,trims, joins) can be elements in this set. Catia knows exactly how many there are in this set.

It is defined by the .Count method but to loop it is better to use the For Each statement. This will loop through all the entities in the set in my case name MySurfaces

Sample code

Sub CATMain()

Set partDocument1 = CATIA.ActiveDocument

Set part1 = partDocument1.Part

Set hybridBodies1 = part1.HybridBodies

Set hybridBody1 = hybridBodies1.Item("MySurfaces")

Dim s

For Each s in hybridBody1 ' select each element in my set

'........Your Code Here

Next s ' Loop

End Sub


P.s Your code

Set reference3 = part1.CreateReferenceFromBRepName("Rsur:(Face:(Brp:(Pad.1;0:(Brp:
(GSMBiDim.1;2)));None:();Cf9());WithTemporaryBody;WithoutBuildError;
WithSelectingFeatureSupport)",pad1)

This is referencing the surface of a solid element and not a surface directly. It is better to use the method

.CreateReferenceFromObject

Regs
 
Regs,

Yeah, I have that loop in my macro. The loop works as I need it to. And I do realize I am calling out the face of a solid; I need to in order to draft the solid it pertains to. So, unless there's a better way of somehow referencing that face, that's all I've got for now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor