Ilogic to lock views in drawing

Ilogic to lock views in drawing

dan_inv09
Advisor Advisor
2,415 Views
19 Replies
Message 1 of 20

Ilogic to lock views in drawing

dan_inv09
Advisor
Advisor

I guess I'm just not looking in the right places.

 

I'm looking for the command to lock (or unlock) a view in an .idw

 

I should be able to work the rest to do it for each view on the drawing, but right now I'm stuck trying to find what controls locking the view.

 

If you could point me in the right direction to find the command(s) I would appreciate it. Thanks.

0 Likes
Accepted solutions (1)
2,416 Views
19 Replies
Replies (19)
Message 2 of 20

ekinsb
Alumni
Alumni

What do you mean by "locking a view".  Is this possible in the user interface?


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 3 of 20

dan_inv09
Advisor
Advisor

This

lock.png

 

And I do not know, but I was hoping that it's possible.

 

Do you know where I might try looking?

0 Likes
Message 4 of 20

ekinsb
Alumni
Alumni

In the API help there's a sample titled "Adding Representation Views" that does just this.  I've copied the sample below.  The thing you're looking for is the "DesignViewAssociative" option that's being set.  That's the equivalent of the chain check box that you referenced in the dialog.

 

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

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 5 of 20

dan_inv09
Advisor
Advisor

#1 Why can't I cut and paste the errors from the Edit Rule Dialog?

 

#2 'oBaseViewOptions' is not declared. It may be inaccessible due to its protection level.

 

Now, with the "Call"s and the"Public Sub" and all that, it looks kind of like what you posted is VBA or whatever it's called.

 

I'm trying to use iLogic.

ilogic.png

Maybe that's why nobody ever answers, I put iLogic in the subject line, and everybody thinks, "I could do it with Visual Basic but nobody uses iLogic."

 

So, thanks but, is there a comparable command that will work in iLogic?

Is there an iLogic help where I could find a similar sample?

Are you thinking what I said "Maybe everybody thinks ..." a few lines ago?

0 Likes
Message 6 of 20

dan_inv09
Advisor
Advisor

Okay the the reason I cot that error with oBaseViewOptions was I left out

SyntaxEditor Code Snippet

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

 ("'Let' and 'Set' are no longer supported")

 

but now I get "Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))" which I think was similar to what I was getting a while ago when someone suggested a "NameValueMap" for doing something else - maybe when I was making view reps in subassemblies, or when I tried to put those view reps on a drawing about 4 months ago.

0 Likes
Message 7 of 20

ekinsb
Alumni
Alumni

Here's an iLogic rule that demonstrates what you're trying to do.  You'll need to change the names of the positional and view reps and also the level of detail.  Of course you don't have to use all of those but the sample is just demonstrating all of them.

 

Thanks for this question.  I'm working on a class for Autodesk University regarding iLogic and the Inventor API and you've given me a lot more insight about what I should cover.

 

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

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

  ' 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("PositionalRepresentation", "Position1")
  oBaseViewOptions.Add("DesignViewRepresentation", "View1")
  oBaseViewOptions.Add("DesignViewAssociative", True)

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

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

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

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

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 8 of 20

dan_inv09
Advisor
Advisor

I'm using this, which was originally for changing the scale of all the views

 

SyntaxEditor Code Snippet

 Dim oDrawDoc As DrawingDocument = ThisDrawing.Document
Dim oSheet As Sheet
Dim oSheets As Sheets
Dim oView As DrawingView
  ' Create a new NameValueMap object
Dim oBaseViewOptions As NameValueMap
oBaseViewOptions = ThisApplication.TransientObjects.CreateNameValueMap
Dim oViews As DrawingViews
oSheets = oDrawDoc.Sheets
For Each oSheet In oSheets
oViews = oSheet.DrawingViews
For Each oView In oViews
oBaseViewOptions.Add("DesignViewAssociative", True)
Next
Next

 

 

the bold parts are what I tried to add. Here's the original

 

SyntaxEditor Code Snippet

Dim oDrawDoc As DrawingDocument = ThisDrawing.Document
Dim oSheet As Sheet
Dim oSheets As Sheets
Dim oView As DrawingView
Dim oViews As DrawingViews
Dim oScale As Double
oScale = InputBox("Enter Desired Scale", "Scaler", "1")
oSheets = oDrawDoc.Sheets
For Each oSheet In oSheets
oViews = oSheet.DrawingViews
For Each oView In oViews
If oView.ScaleFromBase = False Then
oView.Scale = oScale
End If
Next
Next

 

See, I do not want to "change the names of the positional and view reps and also the level of detail" because I need it to go through each view. If I could put all the names in I would not need to automate it. I could just go to the one or two views and change them. The problem that is causing me to try and resort to iLogic is that I need to do it for something like 30 views sometimes.

 

So the whole problem hinges on finding a command in iLogic that will work in the "for each" statement.

 

[I had just copied that scale iLogic from somewhere. I just copied it and used it and it worked. I've never really looked at it. ... I only use one sheet per drawing - I do not need the "For each oSheet in oSheets ... Next". Well, at least I learned one thing today.]

0 Likes
Message 9 of 20

ekinsb
Alumni
Alumni

Ok, your latest response helps a lot.  Everything so far has been about creating new drawing views.  Not changing the settings for an existing drawing view.  Here's a modified version of your rule that should do what you want.  You'll need to change the name of the design view to the name of a design view that exists or you can use "Default" which will work in all cases.

 

Dim oDrawDoc As DrawingDocument = ThisDrawing.Document
For Each oSheet As Sheet In oDrawDoc.Sheets
	For Each oView As DrawingView In oSheet.DrawingViews
		oView.SetDesignViewRepresentation("View1", True)
	Next
Next

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 10 of 20

dan_inv09
Advisor
Advisor

Can't I have it just lock whatever view rep is already set?

 

I might be able to integrate this into the create view iLogic, but I don't think this is quite what I need for a stand alone rep lock.

 

See, in my case I have a multibody part for my welded housing. I convert that into an assembly. Then I had iLogic make a view rep for each piece and I recently had someone help me out with iLogic to place all those views on a drawing.

 

I recently had to add a gusset to a housing and the gusset showed up in every view for every piece in the weldment on the drawing, so I had to go through that whole drawing and click the lock for each view. That's why I was looking for iLogic that could go through each view and lock the rep.

(Sometimes a new unit is close enough to an old one that I will "copy design" and need to deal with drawings created at different stages in this iLogic adventure, so sometimes some might need just a little, if you know what I mean.)

0 Likes
Message 11 of 20

ekinsb
Alumni
Alumni

Unfortunately, the name of the view rep that was used when the view was initially placed is not available through the API.  I know that the dialog shows it so Inventor has stored it but the API doesn't currently expose it.  iLogic is built on top of the API so if the API doesn't provide access to something it's not possible for iLogic to provide it either.

 

If the view isn't associative to a view rep (the box is unchecked) then there isn't any kind of association to that name in the field.  The view rep could have even been deleted so it's not always possible to use the name that's in the field.  Although I do realize that would not be the normal case and it would be nice to have access to that name to be able to create the association but it's currently just not possible.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 12 of 20

dan_inv09
Advisor
Advisor

So you can't lock it unless it's locked?

 

There's no way to lock whatever the current view is?

(Like leaving part of the field empty: "oView.SetDesignViewRepresentation(, True)" or something?)

 

What if we just go back to the fundamental problem:

I copied an old design and the parts of the weldment are all on one drawing but I added or replaced some parts. The views are not locked to the view reps so the new parts mess up all the views.

I was going to say could we turn off visibility in the views of everything that's not the same as the active rep for that view, but that's exactly the problem we had: if the view's not locked we can't get the name.

 

The thing is that the drawing is almost completely done but there's a big problem in that the views that had all been just one part now have an extra part or two and are all smooshed out of the way and it looks like a big jumbeled mess

0 Likes
Message 13 of 20

ekinsb
Alumni
Alumni

Are the names of the design view representations consistent or is there some way by looking at the list of design views in the part or assembly to figure out which design view you need?

 

Otherwise I don't really see a good solution.  You basically need to set the view to a specific design view representation (and this time making it associative so you don't have this same problem in the future).  From the API we can make a view associative to a design view but we don't know the name of the design view that was used when the view was created. There is not workaround to get that name.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 14 of 20

dan_inv09
Advisor
Advisor

I guess the views should be in the order of the assembly views (and maybe even the parts in the assembly browser where they get their names). But there might be some views that are used on other drawings. And if we lock a Rep other than the one that was already dimensioned, it defeats the whole purpose of working from a copy of an old job.

 

In this thread:

 

http://forums.autodesk.com/t5/inventor-customization/ilogic-for-idw-from-iam/td-p/6321501/highlight/...

 

in rusmwb's reply at 05-23-2016 07:24 AM (is that going to be consistent or would you see a local time where you are?)

 

In the code that starts with:

Public Sub CreateViewForEachRep()

 

Could we add a line that locks the view rep?

 

I assume we could place

oDesView.SetDesignViewRepresentation(oDesView.Name, True)

 

right after the 

Call PlaceBaseView(oSheet, assyDoc, oPoint1, oDesView.Name)

 

No that does not work, you see I only sort of understand what I'm doing with iLogic - I'm completely lost with VBA.

I need help with the syntax. It "expected ="?? Evidently I need some sort of expression, I guess.

 

 

Also, could you post something like

No.

There is no way to do that.
The API does not recognize the current active Rep in the drawing view unless it is already locked, and cannot lock the view Rep without knowing its name.

or however you want to word it - but just the clearest, most concise explanation all alone in a separate post? That way I can select it as the "solution" so if someone comes across this thread they can see right away that you can't do what I was initially hoping to do.

0 Likes
Message 15 of 20

ekinsb
Alumni
Alumni
Accepted solution

To summarize:

 

If you have an existing drawing view that was created using a design view representation but is not associative to the design view representation, there is currently no way to make it associative to that design view representation, if you don't know the name of the design view representation.

 

When using the API to associate a view with a design view representation you have to supply the name of the design view representation and the name that was used when the view was created is not accessible from the API.

 

If you know the name of the design view representation you can use the SetDesignViewRepresentation method of the DrawingView object where the first argument is the name of the design view representation and the second argument is if it's to be associative or not.

 

oView.SetDesignViewRepresentation("View1", True)

 

It is possible to create a new view using the API that is associated to the design view representation.  The VBA code below demonstrates that.

 

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

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

  ' 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("PositionalRepresentation", "Position1")
  oBaseViewOptions.Add("DesignViewRepresentation", "View1")
  oBaseViewOptions.Add("DesignViewAssociative", True)

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

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

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

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

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 16 of 20

dan_inv09
Advisor
Advisor

This should probably go in the other thread but, the first view I placed before running  rusmwb's VBA was a weldment with Machining but all the views it generated are Assembly. (Which is actually what I wanted, but I'd rather have some control over it.)

 

Can weldment  features for the drawing view be controlled wit the API? Like placing a view for each "Preparation"?

0 Likes
Message 17 of 20

ekinsb
Alumni
Alumni

Yes, you can place views of the different weldment states.  For the AdditionalOptions argument of the AddBaseView method you can pass in a value that specifies which weldment state you want.  Below is an example creating a view showing the welds but you can also use kAssemblyFeatureGroup, kMachiningFeatureGroup, or kPreperationsFeatureGroup.

 

    options = ThisApplication.TransientObjects.CreateNameValueMap
    options.Add("WeldmentFeatureGroup", WeldmentFeatureGroupEnum.kWeldsFeatureGroup)
    view = drawViews.AddBaseView(weldment, tg.CreatePoint2d(10, 10), 0.25, kFrontViewOrientation, kHiddenLineDrawingViewStyle, , , options)

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 18 of 20

dan_inv09
Advisor
Advisor

Okay, it's giving me errors with:

 

  oBaseViewOptions.Add("PositionalRepresentation", "Position1")
  oBaseViewOptions.Add("DesignViewRepresentation", "View1")
  oBaseViewOptions.Add("DesignViewAssociative", True)

 

It says syntax error

0 Likes
Message 19 of 20

ekinsb
Alumni
Alumni

If you have VBA code, you need to add "Call" to the beginning of each of the lines.  Anytime you call a method with multiple arguments and enclose them in parentheses you need to use the "Call" statement.  In VBA the parentheses are optional but if you use them you have to use Call.  VB.NET doesn't need the Call statement but it requires parentheses.  Personally, I like parentheses so I use the Call statement in VBA.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 20 of 20

Anonymous
Not applicable
0 Likes