iLogic for idw from iam

iLogic for idw from iam

dan_inv09
Advisor Advisor
3,301 Views
32 Replies
Message 1 of 33

iLogic for idw from iam

dan_inv09
Advisor
Advisor

It seems when it gets to this line:

 

oBaseView = oSheet.DrawingViews.AddBaseView(oAsmCompDef,oPoint,2,kFrontViewOrientation,kHiddenLineRemovedDrawingViewStyle,,,oBaseViewOptions)

 

it gives this error:

 

Error in rule: Rule0, in document: DUMMY WELDMENT.iam

Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor._Document'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{70109AA1-63C1-11D2-B78B-0060B0EC020B}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

 

 

Now, let's start off by stating that I have absolutely no idea what I'm doing. I'm just grabbing bits and pieces from other peoples code and trying to reconcile the variables. If someone could just point me in the direction of some sort of syntax so I can figure out what is supposed to be in that statement, that would be great, but I look at it and it all seems like gobbledygook and maybe the error is saying that it is.

 

I'll attach the whole code if anyone wants to point and laugh. (But if you had some constructive criticism that'd be okay too.)

 

I've got something misplaced or misspelled or something but I really don't know what it's supposed to look like, so I could really use some help. If anyone can even just tell me where to go to find out what these commands are supposed to look like it would be a big help.

 

Thank you for taking the time to assist me. I really appreciate it.

0 Likes
3,302 Views
32 Replies
Replies (32)
Message 21 of 33

dan_inv09
Advisor
Advisor

The views part worked great (with 30 something parts, the view location increment put stuff way off to the side but I can figure out how to get rid of that - I've got to position everything anyway, so there's not problem if they're all right on top of each other).

 

[Where'd they put the spellcheck button? Ah, that's clever - it's always checking. What are the forums going to be like when everyone is automatically spellchecked? I suppose you can just ignore it, right?]

0 Likes
Message 22 of 33

dan_inv09
Advisor
Advisor

Can we put something in here to lock the views to the reps?

 

I was working with somebody else and they said it involved something like:

 

' Create a new NameValueMap object
  Dim oBaseViewOptions As NameValueMap
  oBaseViewOptions = ThisApplication.TransientObjects.CreateNameValueMap

 

  ' Set the representations to use when creating the base view.
  oBaseViewOptions.Add("DesignViewAssociative", True)

 
  ' Create a base view.
  Dim oBaseView As DrawingView
  oBaseView = oSheet.DrawingViews.AddBaseView(oModel, oPoint, 2, _
                    ViewOrientationTypeEnum.kIsoTopLeftViewOrientation, _
                    DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle,,, _
                    oBaseViewOptions)

 

but the

oBaseViewOptions.Add

is giving me a syntax error

 

(I kept asking for iLogic and he kept giving me vba and I kept saying I needed it to cycle through a bunch of things and he only gave me code where "Here is where you put THE name of THE view ..." so I think he knew I wouldn't try his vba code. So he gave me code with syntax errors and then had that marked the solution - I think the original poster should be the only one who can declare the issue solved, but I guess I must be wrong.)

0 Likes
Message 23 of 33

Anonymous
Not applicable

 

It is not necessary to create a name value map to provide the view representation name to the AddBaseView method.

 

DrawingViews.AddBaseView Method

Parent Object: DrawingViews

Description

Method that creates a new base . The newly created DrawingView is returned.

Syntax

DrawingViews.AddBaseView( Model As Document, Position As Point2d, Scale As Double, ViewOrientation As ViewOrientationTypeEnum, ViewStyle As DrawingViewStyleEnum, [ModelViewName] As String, [ArbitraryCamera] As Variant, [AdditionalOptions] As Variant ) As DrawingView

 

ModelViewNameOptional input String that defines the design view name for assembly files, or the presentation view name for presentation files. This argument is ignored if the document type specified by the Model argument is a part file (.ipt).

 

As you can see in the above syntax ModelViewName is an optional argument you can pass in as a string.

 

 In my previous posts oDesView was the variable name used to pass it in to the Sub routine.

In the Sub routine "viewName" is the variable. Here is a portion of that code.

 

Dim oDesView As DesignViewRepresentation
   
    For Each oDesView In oRepMgr.DesignViewRepresentations
        If oDesView.Name <> "Default" And oDesView.Name <> "Master" Then
           
            Dim oPoint1 As Point2d
            Set oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(ptx, 11)
           
            Call PlaceBaseView(oSheet, assyDoc, oPoint1, oDesView.Name)
                       
        End If
        ptx = ptx + 14
    Next

 

Public Sub PlaceBaseView(ByRef sheet As Inventor.sheet, _
                        ByRef assyDoc As AssemblyDocument, _
                        ByRef ctrpoint As Point2d, _
                        ByRef viewName As String)

    'define view orientation
    Dim vieworient1 As ViewOrientationTypeEnum
    Let vieworient1 = ViewOrientationTypeEnum.kFrontViewOrientation

    'define view style
    Dim viewstyle1 As DrawingViewStyleEnum
    Let viewstyle1 = DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle
   
    Dim oFaceView As DrawingView
    Set oFaceView = sheet.DrawingViews.AddBaseView(assyDoc, ctrpoint, 0.5, vieworient1, viewstyle1, viewName)

End Sub

 

 

 

0 Likes
Message 24 of 33

dan_inv09
Advisor
Advisor

That's not exactly what I was concerned about.

 

The main issues I'm having are that:

1. the name value map syntax - oBaseViewOptions.Add("DesignViewAssociative", True) is not right

 

and whether we do it that way or not

2. I need the drawing view locked to the assembly view rep

 

I think that what I need is in

[ArbitraryCamera] As Variant, [AdditionalOptions] As Variant

 

What exactly is meant by ArbitraryCamera?

Could that be what I'm looking for?

Do I just put "True" or "Locked" or something there? (Maybe with the quotation marks or something like that?) Or is there some other sort of statement? Or is it something that needs to go into AdditionalOptions somehow? (again, "locked" or perhaps "viewRep=locked" etc.?)

 

 

Yesterday I ended up going to the browser and right clicking each view, going to edit view and checking the little "lock" box. Simple enough. Only forty-four times for this drawing.

As I found out in another thread there is no way to automate that after the fact, but surely there must be a way to roll it into creating the view, right?

 

0 Likes
Message 25 of 33

Anonymous
Not applicable

I believe you can do that by using True with the Associative argument of the SetDesignViewReperenstation Method of the DrawingView object.

 

Here is the syntax from the programming help;

DrawingView.SetDesignViewRepresentation Method

Parent Object: DrawingView

Description

Method that sets a design view representation for a drawing view of an assembly. This method fails for drawing views of parts and presentations and in the case where the model (assembly) is unresolved.

Syntax

DrawingView.SetDesignViewRepresentation( Representation As String, [Associative] As Boolean )

Parameters

NameDescription
RepresentationString that specifies the Design View Representation to set on the drawing view. The method returns a failure if a representation with this name is not found in the referenced assembly.

 

AssociativeOptional input Boolean that indicates whether to associatively apply the design view. If set to True, any changes to the design view in the referenced assembly will show in this view. If not specified, a value of False is used.
0 Likes
Message 26 of 33

Anonymous
Not applicable

In my previous post I am referring to an existing View. To achieve this while adding new views you can pass in the associative flag via the AdditionalOptions argument of the AddBaseView Method with a name value map.

 

Valid values for the NameValue map of the AdditionalOptions argument is shown below:

Name Type Valid Document Type Notes

WeldmentFeatureGroupValue from WeldmentFeatureGroupEnumWeldment 
SheetMetalFoldedModelBooleanSheet metal PartDocumentThe part document must contain a flat pattern if a flat view (False) is specified. If a flat doesn't exist, a folded view will be created.
DesignViewRepresentationStringAssemblyThe name of the design view representation.
DesignViewAssociativeBooleanAssemblyIndicates if the drawing view will be associative to the design view. A design view must be specified.
PositionalRepresentationStringAssemblyThe name of the positional representation.
MemberNameStringPart, AssemblyThe name of the iPart or iAssembly member.
PresentationViewStringPresentationThe name of the presentation view.
PresentationViewAssociativeBooleanPresentationIndicates if the view should be associative to the presentation view. A presentation view must be specified

 

Here is a snippit from the help;

 

Public Sub AddBaseViewWithRepresentations()
  ' Set a reference to the drawing document.
  ' This assumes a drawing document is active.
  Dim oDrawDoc As DrawingDocument
  Set oDrawDoc = ThisApplication.ActiveDocument

  'Set a reference to the active sheet.
  Dim oSheet As Sheet
  Set oSheet = oDrawDoc.ActiveSheet

  ' Create a new NameValueMap object
  Dim oBaseViewOptions As NameValueMap
  Set oBaseViewOptions = ThisApplication.TransientObjects.CreateNameValueMap

  ' Set the representations to use when creating the base view.
  Call oBaseViewOptions.Add("PositionalRepresentation", "MyPositionalRep")
  Call oBaseViewOptions.Add("DesignViewRepresentation", "MyDesignViewRep")
  Call oBaseViewOptions.Add("DesignViewAssociative", True)

  ' Open the model document (corresponding to the "MyLODRep" representation).
  Dim strFullDocumentName As String
  strFullDocumentName = ThisApplication.FileManager.GetFullDocumentName("C:\tempreps.iam", "MyLODRep")

  Dim oModel As Document
  Set oModel = ThisApplication.Documents.Open(strFullDocumentName, False)

  ' Create the placement point object.
  Dim oPoint As Point2d
  Set oPoint = ThisApplication.TransientGeometry.CreatePoint2d(25, 25)

  ' Create a base view.
  Dim oBaseView As DrawingView
  Set oBaseView = oSheet.DrawingViews.AddBaseView(oModel, oPoint, 2, _
  kIsoTopLeftViewOrientation, kHiddenLineRemovedDrawingViewStyle, _
      , , oBaseViewOptions)
End Sub
0 Likes
Message 27 of 33

dan_inv09
Advisor
Advisor

so the syntax problem was the lack of the word Call?

 

so this should work?

 

Public Sub CreateViewForEachRep()
    ' Set a reference to the drawing document.
    ' This assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.ActiveDocument
   
    'Set a reference to the active sheet.
    Dim oSheet As sheet
    Set oSheet = oDrawDoc.ActiveSheet
   
    Dim viewScale As Double
    Let viwScale = 0.1875
   
    Dim ptx As Long
    Let ptx = 0
   
   
    'this assumes that view1 is of the full assembly
    Dim assyDocName As String
    Let assyDocName = oSheet.DrawingViews.Item(1).ReferencedDocumentDescriptor.FullDocumentName
       
    Dim assyDoc As AssemblyDocument
    'open assembly doc invisibly
    Set assyDoc = ThisApplication.Documents.Open(assyDocName, False)
       
    Dim oAssyCompDef As AssemblyComponentDefinition
    Set oAssyCompDef = assyDoc.ComponentDefinition
   
    Dim oRepMgr As RepresentationsManager
    Set oRepMgr = oAssyCompDef.RepresentationsManager
   
    Dim oDesView As DesignViewRepresentation
   
    For Each oDesView In oRepMgr.DesignViewRepresentations
        If oDesView.Name <> "Default" And oDesView.Name <> "Master" Then
           
            Dim oPoint1 As Point2d
            Set oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(ptx, 11)
           
            Call PlaceBaseView(oSheet, assyDoc, oPoint1, oDesView.Name)
                       
        End If
        ptx = ptx + 14
    Next
     
      'close assembly doc
      assyDoc.Close (False)

 

End Sub

Public Sub PlaceBaseView(ByRef sheet As Inventor.sheet, _
                        ByRef assyDoc As AssemblyDocument, _
                        ByRef ctrpoint As Point2d, _
                        ByRef viewName As String)

    'define view orientation
    Dim vieworient1 As ViewOrientationTypeEnum
    Let vieworient1 = ViewOrientationTypeEnum.kFrontViewOrientation

    'define view style
    Dim viewstyle1 As DrawingViewStyleEnum
    Let viewstyle1 = DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle

 

' Create a new NameValueMap object
  Dim oBaseViewOptions As NameValueMap
  Set oBaseViewOptions = ThisApplication.TransientObjects.CreateNameValueMap

  ' Set the representations to use when creating the base view.
  Call oBaseViewOptions.Add("DesignViewAssociative", True)

    
    Dim oFaceView As DrawingView
    Set oFaceView = sheet.DrawingViews.AddBaseView(assyDoc, ctrpoint, 0.5, vieworient1, viewstyle1, viewName, , oBaseViewOptions)

End Sub

0 Likes
Message 28 of 33

dan_inv09
Advisor
Advisor

That works.

 

It was just "call" that's been giving me fits for about a month now.

 

 

You see, I don't have any sort of a clue about the overall syntax of vba. So, if someone tells me, "'x y z' is the command you need." I will just put 'x y z'. Then when it doesn't work I get frustrated and set it aside and try and move on, when it might just be a case of whoever told me assumed I knew it needed call or set or =something or 'x y z' goes in 'a b c' to make it right.

I need a class or video tutorial or book or something that will help me learn the fundamentals so that I don't make that sort of mistake. For now I still need everything spelled out for me.

0 Likes
Message 29 of 33

xiaodong_liang
Autodesk Support
Autodesk Support
Hi,

if you are looking for the tutorials of Inventor API, this is the portal that might help you:
http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=1079044

In addition, we have series DevTVs on the modules of Inventor API:
http://adndevblog.typepad.com/manufacturing/2013/05/api-webcast-archive.html

while if what you need is VBA fundamentals, that might turn to MSDN help.
0 Likes
Message 30 of 33

Anonymous
Not applicable

Could this code be tweaked to do the following:

 

place sheet metal flat patterns (scale 1:1), using ilogic?

 

I've already found code (ilogic) to open an assembly, apply sheet metal rules & create a flat pattern.

 

Being able to place these into one dwg for cutting/punching would be a great help.

 

 

 

Thanks

 

Andrew

 

 

0 Likes
Message 31 of 33

adam.nagy
Autodesk Support
Autodesk Support

Hi Andrew,

 

Have a look at this:

http://forums.autodesk.com/t5/inventor-customization/ilogic-how-to-place-flat-pattern-on-the-drawing...

 

The relevant part is:

'False = flat pattern view
oBaseViewOptions.Add("SheetMetalFoldedModel", False)

 



Adam Nagy
Autodesk Platform Services
0 Likes
Message 32 of 33

Anonymous
Not applicable

 

Thankyou - I've based my project on this link...(the one you pointed me to)..

 

 

http://forums.autodesk.com/t5/inventor-customization/ilogic-how-to-place-flat-pattern-on-the-drawing...

 

 

 

I’ve been looking at the code above – I only want the flat pattern & not the three view – I’ve managed to get around this.

 

I want multiple parts on one drawing.

 

I have an idea – to save the drawing as a template for part one & reuse that template for part two. However I can’t see where the source document is:

 

    'Define IDW Template File Location

    'oDrawingDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, "C:\Temp\my template.idw", True)

    oDrawingDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, "", True)

   oSheet = oDrawingDoc.Sheets.Item(1)

   

      ' Create a new NameValueMap object

  Dim oBaseViewOptions As NameValueMap

  oBaseViewOptions = ThisApplication.TransientObjects.CreateNameValueMap

 

 

Generally sheet metal boxes have several parts which need flattening & nesting into a standard size sheet – I need to provide this geometry.

Having all the parts on one drawing is good.

0 Likes
Message 33 of 33

adam.nagy
Autodesk Support
Autodesk Support

In case of that sample code the source document is the one where you run the iLogic rule:

 

oPartDoc = ThisDoc.Document


Adam Nagy
Autodesk Platform Services
0 Likes