Auto Dimensions Using vba and ilogic works in one view and not the other???

Auto Dimensions Using vba and ilogic works in one view and not the other???

Anonymous
Not applicable
2,136 Views
9 Replies
Message 1 of 10

Auto Dimensions Using vba and ilogic works in one view and not the other???

Anonymous
Not applicable

So I have this code:  SyntaxEditor Code Snippet

Dim oDrawDoc As DrawingDocument = ThisDoc.Document
 
Dim oSheet As Sheet = oDrawDoc.ActiveSheet
 
Dim oDrawView As DrawingView = oSheet.DrawingViews(1)

Dim oGeneralDimensionsEnum As GeneralDimensionsEnumerator
oGeneralDimensionsEnum = oSheet.DrawingDimensions.GeneralDimensions.Retrieve(oDrawView)
 
Dim PrefixStr As String = "RDT_"
 
Dim oGeneralDimension As GeneralDimension

For Each oGeneralDimension In oGeneralDimensionsEnum
    Dim oParameter As Parameter
    oParameter = oGeneralDimension.RetrievedFrom.Parameter
 
    If oParameter.DrivenBy.count <> 0 Then
        Dim oDrivenByParameter As Parameter
        For Each oDrivenByParameter In oParameter.DrivenBy
            If InStr(oDrivenByParameter.Name, PrefixStr) = 0 Then
                oGeneralDimension.Delete
            End If
        Next
                Else
        If InStr(oParameter.Name, PrefixStr) = 0 Then
            oGeneralDimension.Delete
        End If
    End If
Next

 

I found this online, I did not create this as I am a novice with vba.  It works perfectly for a TopView.  

However, when I apply the same code to a different view that is isometric,  it gives me the normal general error that says, nope not going to work.  Gives no guidance as to where the problem might be.  

Any ideas would be greatly appreciated.  I am wondering if it has anything to do with isometric view dimensions are no longer linear or horizontal.  Maybe... might need a different type of dimension.  But not sure what one to use.

I changed the drawing view number and the prefix slightly as I do not want the same dimensions again.  

 

The following are the messages that are kicked out to me.

 

Error in rule: AutoDim2, in document: IRW Dev-1.dwg

Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))

 

System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.GeneralDimension.Delete()
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

0 Likes
2,137 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable

So, after a few days of silence I am adding the drawing that I am using.  So you can see the error and what the code does.  

The top View is doing exactly what I want as far as the dimensions are concerned.  The Isoview is where the error occurrs.

In the isoview there is a height dimension that I would like to lable.  You are able to do that in AutoCAD, so the desire is to have the drawing match the AutoCAD version.

In the model I created a point that is floating in space in a sketch, then dimensioned the point to the base of the drawing.  That is the dimension that I cannot get to populate automatically.  Its called "RDT1_Height"  The ilogic rule is autodim2 for the isoview and autodim1 for the topview.

 

 

This is Inventor 2016.

 

Does anyone see the reason it works in one view and not the other?

0 Likes
Message 3 of 10

MechMachineMan
Advisor
Advisor
There's a lot of small things that could be throwing it off. I have never tried dimensions with VBA/Vb.net as it is complex and too tough to meet our standards.

However, a further step you could take is to convert your code to VBA and use the VBA editor to further debug it.

Good luck!

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 4 of 10

adam.nagy
Autodesk Support
Autodesk Support

Hi,

 

Yes, the best thing would be to migrate the code to VBA, which only requires a few changes in the code.

The reverse of what's shown here: http://adndevblog.typepad.com/manufacturing/2015/11/convert-vba-to-net-ilogic.html

 

Then you could see which dimension's Delete() function is throwing the error.

 

Cheers,



Adam Nagy
Autodesk Platform Services
0 Likes
Message 5 of 10

Anonymous
Not applicable

So Converted it to VBA and am trying to debub the code line by line.  Now it throws an error at each line.  

I cannot get passed the oDrawDoc = ThisDocument.Document line.  It keeps throwing the code "method or data member not found"  

It highlights the word Document.  Does not like that decleration???  I tried all types of documents and all options using the intellisense... To no avail.  

There appears to be something wrong with how I declared the odrawdoc?

 

Sub Main()
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisDocument.Document
Dim oSheet As Sheet
Set oSheet = oDrawDoc.ActiveSheet
Dim oDrawView As DrawingView
Set oDrawView = oSheet.DrawingViews(2)
Dim oGeneralDimensionsEnum As GeneralDimensionsEnumerator
Set oGeneralDimensionsEnum = oSheet.DrawingDimensions.GeneralDimensions.Retrieve(oDrawView)

Dim PrefixStr As String
Let PrefixStr = "RDT1_"
Dim oGeneralDimension As GeneralDimension

For Each oGeneralDimension In oGeneralDimensionsEnum
Dim oParameter As Parameter
Set oParameter = oGeneralDimension.RetrievedFrom.Parameter

If oParameter.DrivenBy.Count <> 0 Then
Dim oDrivenByParameter As Parameter
For Each oDrivenByParameter In oParameter.DrivenBy
If InStr(oDrivenByParameter.Name, PrefixStr) = 0 Then
oGeneralDimension.Delete
End If
Next
Else
If InStr(oParameter.Name, PrefixStr) = 0 Then
oGeneralDimension.Delete
End If
End If
Next

 

End Sub

0 Likes
Message 6 of 10

adam.nagy
Autodesk Support
Autodesk Support

VBA does not have ThisDocument, only ThisApplication, so you'd need to use:

Set oDrawDoc = ThisApplication.ActiveDocument

 Cheers,



Adam Nagy
Autodesk Platform Services
0 Likes
Message 7 of 10

Anonymous
Not applicable

There is a new development in this problem.

 

The code will not work for dimensions at all in an assembly.  However, when I strip the assembly down to the one part that has the dimensions, the dimensions will appear without any errors.   As soon as I put in the entire assembly, the code will not work at all.

 

Still working on the height dimension as well.

0 Likes
Message 8 of 10

LukeDavenport
Collaborator
Collaborator
The problem will probably be that you need to refer to proxies for
everything in the assembly, like edges, faces etc, will become edgeproxy,
faceproxy etc. Have you allowed for this in your code. Just a guess, I
haven't tried anything out. Luke
0 Likes
Message 9 of 10

Anonymous
Not applicable

Luke,

Thanks for the idea.  I have not tried any proxies for that view as they were not necessary for the top view.  However, I will look in to those and see if I can get them to work. 

 

 

0 Likes
Message 10 of 10

Anonymous
Not applicable

Alright, So proxies is a no go.  At least at this point.  Attempting to figure out how that would work.

 

In the mean time, Attached is a simplified version of the file, the drawing document, and what it is doing.

It seems that there is a simple line in my code that can be adjusted to have the desired result.  I am incredibly close to the desired result.  Just need to delete several more dimensions from the view.  

 

If you have a moment check it out.   The two rules that I am focused on our the Dimensions and dim2.

 

dim2 is the one that needs some editing as it does not produced the desired result.  Open the dwg and you will find what needs to be fixed in the isometric view as I have labeled it accordingly.

 

The assembly file has the code to create the drawing, and the drawing file has the code to add the dimensions.

 

 

Thanks!

0 Likes