Hi all,
I'm attempting to create a model that autmotaically derives ready-to-go drawings. I've gotten pretty far in doing so but have a few issues with regards to dimensioning. As I'm sure you're aware, when the model changes, a dimension to that feature, which has been removed, is also deleted and some those dimensions do not return once the model is changed back.
I have looked into using different view representations, but have found that they do not accommodate feature supression.
My questions are:
Is there a way to program in the dimensioning of a view
Create center points for of of the holes and center lines
And for a feature note such as "Hole and Thread" dimensioning, when the model expands, the leader and text length do not change and proceed into the view. Is there a way to fix or anchor the text to a certain spot on the drawing, and have the leader length expand and change accordingly to that point.
If you would like farther information, or think a similar question would help, please ask. Thanks in advance for any help.
Mitch
Solved! Go to Solution.
Solved by mehatfie. Go to Solution.
Yes, that's what I suspect as well. I'm not sure why it didn't work when I directly copied and pasted the Style the first time. When I did it the second time it worked, just a weird glitch in the system I assume
Code is so incredibly finicky, if there was an extra space at the end of the string or something dumb like that it would be enough for it to fail.
Hello Again All,
My code "was" working quite nicely and doing what I wanted. But I've apparently done something which I thought would improve the code and it has only made it terribly worse.
I have spent the whole day trouble shooting and can't figure out what is wrong with the code.
Attached you'll find the full code as well as 2 sceenshots of an example problem of what's going wrong. I don't understand that when I ask the sub to find me a variable that is 20.375, it finds me a line that is 7/16......
Any help is appreciated
Thanks
Mitch
If it aint broke, don't fix it!
I strongly suggest keeping regular manual back ups of these sorts of projects. I keep a sub folder next to any of these sort of heavily coded documents with copies made with the extensions changed to a .bak.
Nothing pops out to my eye going through your posted code. I'll think about in the back of my head for a while.
Ok. I've re-writtent the whole code in a different rule, and changed a few aspects of it to clean it up, and now it works beautifully! Much better than before! It's actually doing what I tell it to do and not being stubborn.
I have tried a few different ways to get overall dimensions but all of them have returned an error.... being my favorite of them: "Catastrophic Failure"
TEST 1:
I after finding the top most drawing curve and dimensioning it through my Function, I proceed to return one of the Intents I used for placing the dimension. In my main sub I created a variable (Dim oGeoIntent1 As GeometryIntent) and set this variable = to this Function (ie. oGeoIntent1 = CreateLinearDimension (Blah, Blah, Blah))
I did this for the top most dimension and the bottom dimension. I then created a 2d Point and attempted to create a dimension using the Intents I returned through this Function
oDimension = oDrawingDoc.Sheets(1).DrawingDimensions.GeneralDimensions.AddLinear (oPt, oGeoIntent1, oGeoIntent2, kLinearDimensionType)
This returned the Catastrophic error
TEST 2:
Instead of returning the intent point through the function, I returned the drawing curve that was used and tried to make this line the geometry intent as if you would manually select it while dimensioning.
Dim oPt As Point2d
Dim oGeoIntent1 As GeometryIntent
Dim oGeoIntent2 As GeometryIntent
Dim oLine1 As DrawingCurve
Dim oLine2 As DrawingCurve
oLine1 = CreateLinearDimension (______)
oLine2 = CreateLinearDimension (______)
oGeoIntent1 = oDrawingDoc.Sheets(1).CreateGeometryIntent(oLine1)
oGeoIntent2 = oDrawingDoc.Sheets(1).CreateGeometryIntent(oLine2)
oPt = ThisApplication.TransientGeometry.CreatePoint2d(5, 5)
oDimension = oDrawingDoc.Sheets(1).DrawingDimensions.GeneralDimensions.AddLinear (oPt, oGeoIntent1, oGeoIntent2, kLinearDimensionType)
This returned a Catastrophoc Error as well
QUESTION:
Does anyone know where I'm going wrong?
Or has anyone found a way to create a dimension like this? See the attached photo
Have a Happy Easter if you Celebrate it and Thank a Lot!
Mitch
Is there anyone who knows how to get an Overall Dimension as shown Above?
I've progressed quite far in the drawing and have a much better understanding of the API, but there are still somethings I'm having trouble figuring out.
Any help is welcome
Thanks
Mitch
Sorry Mitch, I think you have a much better understanding of the drawing environment and creating dimensions then I do. I've found that once you get into more and more advanced topics you have a much harder time finding help. There seems to be less people that know how to do it and only a small percentage of them want to share their knowledge.
No problem, that's what I figured as well.
If I can help you at all let me know, as I'll be able to help until the end of the month.
I couldn't have gotten as far as I have without the initial help from you guys
So we’re sort of working on the same thing, but going about it in a different way. I started off just wanting to see if it was even possible to automate dimensions, got frustrated, and then stopped. It was only recently that I was able to find the time to start the project again, only this time, actually making some progress on the matter. Because this is all still in project testing, the below code is awful. I should also note that it is made in VBA 6.5 (so no try / catches), and the method for narrowing down the intent / point2d was stolen from a different post on these forums from a long time ago (so props to you, whoever you are!).
Needless to say this code will look for a sheet metal part that has been pathed directly by you (via hard coding because this is a sexy test), and will then throw the flat pattern onto the open drawing page. Then it will go through all of the curves and attempt to make dimensions using the style you’ve selected. As of now it makes an overall X and an overall Y dim (Y dim being the one that you seem to be having trouble with).
I’m not sure if it will help but I certainly hope that it does.
Option Explicit Public Sub FlatPlusDims() ' 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 options to use when creating the base view. Call oBaseViewOptions.Add("SheetMetalFoldedModel", False) ' Open the sheet metal document invisibly Dim oModel As Document Set oModel = ThisApplication.Documents.Open("D:\Some\Path\To\This\Part.ipt", False) ' Create the placement point object. Dim oPoint As Point2d Set oPoint = ThisApplication.TransientGeometry.CreatePoint2d(0, 0) ' Create a base view. Dim oBaseView As DrawingView Set oBaseView = oSheet.DrawingViews.AddBaseView(oModel, oPoint, 1, _ kDefaultViewOrientation, kHiddenLineRemovedDrawingViewStyle, _ , , oBaseViewOptions) Dim oNewView As DrawingView 'Set oNewView = oSheet.DrawingViews.Item(1) 'Debug.Print oNewView.Name 'Debug.Print oNewView.Position.X 'Debug.Print oNewView.Position.Y 'Debug.Print oDrawDoc.DisplayName 'Debug.Print oDrawDoc.Sheets.Count Dim oCheat As Sheet Dim i As Integer Dim oPageString As String Dim oPageCount As Integer 'For i = 1 To oDrawDoc.Sheets.Count Step 1 'Set oCheat = oDrawDoc.Sheets.Item(i) 'If oCheat.ExcludeFromCount = False Then 'oPageCount = 1 'End If 'If oCheat.Name = "Flat Patterns:" & oPageCount Then 'Debug.Print "Item: " & i & " is a flat pattern sheet!" 'Else 'Debug.Print i 'Debug.Print 'End If 'oPageString = Right$(oCheat.Name, Len(oCheat.Name) - (Len(oCheat.Name) - 1)) 'If IsNumeric(oPageString) = False Then 'oPageCount = 0 'Else 'oPageCount = CInt(oPageString) 'End If 'If oCheat.ExcludeFromCount = False Then ' If oCheat.Name = "Flat Patterns:" & oPageCount Then ' Debug.Print "Item: " & i & " is a flat pattern sheet! It is page number: " & oPageCount ' End If 'End If 'Debug.Print "Sheet :" & oCheat.Name & " ,is Item : " & i & " The Page is :" & oPageCount 'Next Dim TestCurve As DrawingCurve Dim TestSeg As DrawingCurveSegment Dim NewColor As Color Set NewColor = ThisApplication.TransientObjects.CreateColor(255, 0, 0) Dim yMin As Double Dim yMax As Double Dim xMin As Double Dim xMax As Double Dim yMinPoint As Point2d Dim yMaxPoint As Point2d Dim yMinCurve As DrawingCurve Dim yMaxCurve As DrawingCurve Dim xMinPoint As Point2d Dim xMaxPoint As Point2d Dim xMinCurve As DrawingCurve Dim xMaxCurve As DrawingCurve For Each oNewView In oSheet.DrawingViews yMin = oNewView.Height yMax = 0 xMin = oNewView.Width xMax = oNewView.Left For Each TestCurve In oNewView.DrawingCurves Set NewColor = ThisApplication.TransientObjects.CreateColor(255, 0, 0) TestCurve.Color = NewColor TestCurve.LineWeight = 2 For Each TestSeg In TestCurve.Segments If TestCurve.CurveType <> kCircularArcCurve Then 'Debug.Print "Start Point Y: " & TestSeg.StartPoint.Y 'Debug.Print "End Point Y : " & TestSeg.EndPoint.Y 'On Error GoTo Line Next Dim ErrorCheckingSPY As Boolean Dim ErrorCheckingEPY As Boolean Dim ErrorCheckingSPX As Boolean Dim ErrorCheckingEPX As Boolean On Error GoTo ErrHandlerSPY: ErrorCheckingSPY = IsError(TestSeg.StartPoint) On Error GoTo ErrHandlerEPY: ErrorCheckingEPY = IsError(TestSeg.EndPoint) If ErrorCheckingSPY = False Then If Not (TestSeg.StartPoint Is Nothing) Then If TestSeg.StartPoint.Y <= yMin Then yMin = TestSeg.StartPoint.Y Set yMinPoint = TestSeg.StartPoint Set yMinCurve = TestSeg.Parent End If If TestSeg.StartPoint.Y >= yMax Then yMax = TestSeg.StartPoint.Y Set yMaxPoint = TestSeg.StartPoint Set yMaxCurve = TestSeg.Parent End If If TestSeg.StartPoint.X <= xMin Then xMin = TestSeg.StartPoint.X Set xMinPoint = TestSeg.StartPoint Set xMinCurve = TestSeg.Parent End If If TestSeg.StartPoint.X >= xMax Then xMax = TestSeg.StartPoint.X Set xMaxPoint = TestSeg.StartPoint Set xMaxCurve = TestSeg.Parent End If End If End If If ErrorCheckingEPY = False Then If Not (TestSeg.EndPoint Is Nothing) Then If TestSeg.EndPoint.Y <= yMin Then yMin = TestSeg.EndPoint.Y Set yMinPoint = TestSeg.EndPoint Set yMinCurve = TestSeg.Parent End If If TestSeg.EndPoint.Y >= yMax Then yMax = TestSeg.EndPoint.Y Set yMaxPoint = TestSeg.EndPoint Set yMaxCurve = TestSeg.Parent End If If TestSeg.EndPoint.X <= xMin Then xMin = TestSeg.EndPoint.X Set xMinPoint = TestSeg.EndPoint Set xMinCurve = TestSeg.Parent End If If TestSeg.EndPoint.X >= xMax Then xMax = TestSeg.EndPoint.X Set xMaxPoint = TestSeg.EndPoint Set xMaxCurve = TestSeg.Parent End If End If End If 'Else End If Next Set NewColor = ThisApplication.TransientObjects.CreateColor(0, 0, 0) TestCurve.Color = NewColor TestCurve.LineWeight = 3.9370078740157E-03 Next Debug.Print "yMin: " & yMinPoint.X & " " & yMinPoint.Y & " yMax: " & yMaxPoint.X & " " & yMaxPoint.Y Debug.Print "xMin: " & xMinPoint.X & " " & xMinPoint.Y & " xMax: " & xMaxPoint.X & " " & xMaxPoint.X Dim intentMinY As GeometryIntent Set intentMinY = oDrawDoc.ActiveSheet.CreateGeometryIntent(yMinCurve, yMinPoint) Dim intentMinX As GeometryIntent Set intentMinX = oDrawDoc.ActiveSheet.CreateGeometryIntent(xMinCurve, xMinPoint) Dim intentMaxY As GeometryIntent Set intentMaxY = oDrawDoc.ActiveSheet.CreateGeometryIntent(yMaxCurve, yMaxPoint) Dim intentMaxX As GeometryIntent Set intentMaxX = oDrawDoc.ActiveSheet.CreateGeometryIntent(xMaxCurve, xMaxPoint) Dim XPos As Point2d Dim YPos As Point2d Set YPos = oNewView.Position Set XPos = oNewView.Position YPos.X = YPos.X + (oNewView.Width / 2) + 10 XPos.Y = XPos.Y + oNewView.Top + 10 Dim DimStyle As DimensionStyle Set DimStyle = oDrawDoc.StylesManager.DimensionStyles.Item("SUPER_SEXY_STYLE_NAME") Dim oLinDimY As LinearGeneralDimension Set oLinDimY = oDrawDoc.ActiveSheet.DrawingDimensions.GeneralDimensions.AddLinear(YPos, intentMinY, intentMaxY, kVerticalDimensionType, True, DimStyle) Dim oLinDimX As LinearGeneralDimension Set oLinDimX = oDrawDoc.ActiveSheet.DrawingDimensions.GeneralDimensions.AddLinear(XPos, intentMinX, intentMaxX, kHorizontalDimensionType, True, DimStyle) Next 'Dim oBendCollection As Collection 'Dim oView As DrawingView 'Dim oCurve As DrawingCurve 'Dim oBendNote As BendNote ''Set oView = oSheet.DrawingViews ''Set oCurve = oView.DrawingCurves 'Dim curveCount As Double 'Dim oMovePoint As Point2d 'Dim pX As Double 'Dim pY As Double ' For Each oView In oSheet.DrawingViews 'Set oMovePoint = ThisApplication.TransientGeometry.CreatePoint2d(oView.Width / 2, oView.Height / 2) ' oView.Position = oMovePoint ' For Each oCurve In oView.DrawingCurves ' curveCount = oView.DrawingCurves.Count ' ' If oCurve.EdgeType = kBendDownEdge Or oCurve.EdgeType = kBendUpEdge Then ' 'oBendCollection.Add (oCurve) ' ' Set oBendNote = oSheet.DrawingNotes.BendNotes.Add(oCurve) 'End If 'Next 'Next ErrHandlerSPY: ErrorCheckingSPY = True Resume Next ErrHandlerEPY: ErrorCheckingEPY = True Resume Next End Sub
In the call to GeneralDimensions.AddLinear, kLinearDimensionType doesn't help the function. It is not a predefined constant value. If you look at the DimensionTypeEnum list, this is what is available:
Public Enum DimensionTypeEnum
kAlignedDimensionType = 60161
kHorizontalDimensionType = 60162
kVerticalDimensionType = 60163
kArcLengthDimensionType = 60164
kSymmetricDimensionType = 60165
kDiametricDimensionType = 60166
End Enum
I think kVerticalDimensionType is what you want for your overall dimension. That's what MegaJerk is using in his code.
Thanks for replying MegaJerk,
Like you said, for the most part it's the same concept expect your doing it all in one flow of code while I'm using Subs and Functions.
I believe your adding the dimension by simply taking the 2 intent points (1 on each line) and placing the dimension using these. I actually tried this method myself but it didn't seem to want to work. Maybe it was just something small I missed. I'll give it another shot using this method.
Set oLinDimX = oDrawDoc.ActiveSheet.DrawingDimensions.GeneralDimensions.AddLinear(XPos, intentMinX, intentMaxX, kHorizontalDimensionType, True, DimStyle)
Question though, are your overall dimensions attached to the same drawing curve? Or do they have to attach to 2 completely different curves
Thanks
Mitch
I want to say that they are two different curves, but I could be wrong. I haven't put work in on this in nearly 2 weeks, and only had a few hours to get to the point you see there, so... things are hazy.
Needless to say, the reply under my code laden one, is pointing in the correct direction for you.
Try out kVerticalDimensionType. I think that might just solve your problem without doing anything differently.
Oh Sorry,
Mike must have posted as I was typing my reply and I missed it.
This is true Mike, and probably what went wrong. For my Function to place an angled dimension I use the enums you have shown which is probably why it works fine. I'll write up the code and test this out.
Another quick question then building on this: Can you create the geometry intent based off of the line rather than a point?
Thanks
Mitch
Yes, you can use CreateGeometryIntent on a line, but you need a line AND a point. This is usually an endpoint. In MegaJerk's example he finds the required point coordinates. Or you might be able to use PointIntentEnum:
Public Enum PointIntentEnum
kStartPointIntent = 57857
kEndPointIntent = 57858
kMidPointIntent = 57859
kCenterPointIntent = 57860
kCircularLeftPointIntent = 57861
kCircularRightPointIntent = 57862
kCircularTopPointIntent = 57863
kCircularBottomPointIntent = 57864
End Enum
If you do, remember to add:
Imports Inventor.PointIntentEnum
at the top of your rule.
Ok, yes I've already used the way you've explained on my other functions. I was curious if you could select only the line for the intent as if you manually place a dimension and pick the line instead of a point.
Now that I think of it there is probably programming behind that manual operation that decides which intent point to use
Mitch
Hi Mike,
I believe this is I question for you. I was asked how you would create a FlatPattern View and I've attempted to create one.
I looked at the code in the API help and was able to get it to work in the VBA Editor, but the transition to iLogic is only placing basic views.
I've attached a portion of code which I believe should work, and as you can see, I'm placing a Basic view to ensure that it works, followed by an attempt at a Flat Pattern. Only they both turn out to be that basic view. This code is run from within the part.
The code runs, therefore I'm assuming this is the issue of missing some Imports as you've previously pointed out. I tried placing multiple imports which I believed might effect the code, but there were no changes.
If you could have a look it would be appreciated
Thanks
Mitch
Try adding Nothing near the end of the last line:
oBaseView = oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint2, 0.5, kDefaultViewOrientation, kHiddenLineDrawingViewStyle, "Last Active", Nothing, oBaseViewOptions)
Does anything from this thread help ?
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/iLogic-How-to-place-flat-pattern-on-th...
Yup, that's actually my code
I just got in and tried to create the code, I probably should have checked the other threads first. But the code in there is very very close to what I tried. It look like I needed to:
Dim oBaseView As DrawingView
Dim oFlatView As DrawingView
(I missed doing this when I shrunk the code)
Simple but Costly mistake.
Thanks
Mitch