Ok basically I have an IPT file with a few different 2d sketch blocks I also have a 2d Sketch called "Profile" basically what you would do is edit the "Profile" sketch and Place Block selecting what ever profile you needed to extrude (Square Tube, Angle, Plate,Pin, Round Tube) Im looking for a way to do this with ilogic so far Ive been able to activate the "Profile" Sketch and delete the current block thats placed in the sketch but when I try to insert a new block the code errors out. see code below
Dim oPartDoc As PartDocument oPartDoc = ThisApplication.ActiveDocument Dim oCompDef As PartComponentDefinition oCompDef = oPartDoc.ComponentDefinition Dim oSketches As PlanarSketches oSketches = ThisApplication.ActiveDocument.ComponentDefinition.Sketches Dim oSketch As PlanarSketch oSketch = oSketches.Item("Profile") oSketch.Edit oSketch.sketchblocks.item(1).delete Dim oSketchBlockDef As SketchBlockDefinitions oSketchBlockDef = oCompDef.SketchBlockDefinitions.Item("Plate")
This is where it errors out stating "The Parameter is incorrect" (See attached picture for a screenshot of the "More Info section of the Error Message) Dim oPosition As Point2d oPosition = ThisApplication.TransientGeometry.CreatePoint2d(0, 0) ' Insert the sketch block definition oSketch.SketchBlocks.AddByDefinition(oSketchBlockDef, oPosition) oSketch.exitedit
Hi ComputerGuru666,
I think the issue is that the block called Plate has no internal profiles where as the the tube profiles do, and visa versa. Can you confirm this?
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Hi Curtis
In short Im nottrying to select Inventor profiles Im trying to select blocks that I created
I've drawn these profiles myself and added them to the "Blocks" Folder in the IPT so when I activate the 2d sketch named "Profile" I can then Right Click on "Plate" or "Circle" (or any other block I might add) under the "Blocks" folder and click "Place Block" which then allows me to place the block I chose in that sketch finish editing the sketch and extrude that sketch see attached picture.
Hope this makes sense
Thank you
Hi ComputerGuru666,
I think I follow what you're doing, but I get an error if I try to exchange a block with an internal profile with one that has only one (external) profile, or visa versa.
For instance if I try to exchange a block with a rectangle profile with one that has a circle, it works. If I try to exchange the rectangle profile with a tube profile, I get the error.
I think the solution will be the Combine parameter of the Profiles.AddForSolid method, but I'm not certain.
Do you get errors exchanging blocks that have the same number of profiles? Or only when one block has a different number of profiles?
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Parameters | Description |
Combine | Optional input Boolean that specifies whether to combine the profile paths obtained when this method is used to create a new profile. For instance, let us take the example of a sketch containing two concentric circles. If this argument is specified to be true, the resulting profile will contain 2 profile paths, and the profile path corresponding to the inner circle will have its AddsMaterial flag set to False. Hence, the resulting profile is a circular disc with a circular cut-out. If the Combine flag is specified to be False, the resulting profile will contain 2 profile paths with the AddsMaterial flag set to True for both paths. If the sketch contains text boxes, then the profile paths corresponding to them will always have the AddsMaterial flag set to True irrespective of whether the Combine flag is specified to be True or False. |
Ahh We are getting closer I have fixed the parameter issue however now Im getting a new error when I switch the profile with the ilogic the ilogic properly deletes the existing block in the sketch and then errors out (see attachment)
however if i manually activate the sketch delete whatever block is used for the extruded profile and place a different block and click finish sketch the extrusion updates without issue except if like you said I try to go from a plate to a tube profile.
Ok I have solved the above problem but I am still working on the issue of switching between the tube profile and the plate profile any ideas?
Hi,
I did not see a description on the question "switching between the tube profile and the plate profile" in this thread. Could you elaborate?
Can you provide an explination for the solution that you found ComputerGuru666? I'm trying to get this to work and running into the same issue you're describing.
Thanks.
Shane
I figured out how to change the profiles from a plate to a tube with out anything erroring out here is the code using part of Curtis Waguespacks "selecting all closed profiles code" and making a few small changes and adding a few things so the code would select the extruded feature and then update the new 2d profile for that extruded feature
If ProfileType = "" Then 'Do Nothing Else 'Suppress extruded feature Feature.IsActive("Extruded Profile") = False Dim oPartDoc As PartDocument oPartDoc = ThisDoc.Document Dim oCompDef As PartComponentDefinition oCompDef = oPartDoc.ComponentDefinition Dim oSketches As PlanarSketches oSketches = oCompDef.Sketches Dim oSketch As PlanarSketch oSketch = oSketches.Item("Profile") oSketch.Edit oSketch.sketchblocks.item(1).delete Dim oSketchBlockDef As SketchBlockDefinition oSketchBlockDef = oCompDef.SketchBlockDefinitions.Item(ProfileType) 'multivalue list only containing the names of all blocks oPosition = ThisApplication.TransientGeometry.CreatePoint2d(0, 0) oSketch.SketchBlocks.AddByDefinition(oSketchBlockDef, oPosition) oSketch.exitedit Feature.IsActive("Extruded Profile") = True
'updates the extrusions profile after the the sketch has been changed Dim oExtrude As ExtrudeFeature oExtrude = oCompDef.Features.ExtrudeFeatures.Item("Extruded Profile") 'get the feature Dim oProfile As Profile oProfile = oSketch.Profiles.AddForSolid 'get the profile loops and save to oProfile oExtrude.Profile = oProfile 'update the profile definition for oExtrude oPartDoc.Update 'update the doc End If