- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All,
im trying to get a code to create automaticly a drawing from a part.
i want to have automaticly the wright scale and the dimensions.
im trying all kinds off coding but not one is working on my end.
in the future i want to get more out of this. but im new in the coding
Can someone help me out. we use inventor 2021.
the code what comes nearby is this one. but it doestnt wok completly (i copy paste it its to complex for me)
we have parts sometimes of 1 meter and other times of 12 meter that doesnt work in this code.
f (ActiveSheet.Name <> "Sheet:2") Then Return SheetPlayX = 250 SheetPlayY = 250 deviation_X = -10 deviation_Y = 40 play_between_views = -20 Dim View(0 To 6) As String Dim CenterX(0 To 6) As Single Dim CenterY(0 To 6) As Single Dim ViewHeight(0 To 6) As Single Dim ViewWidth(0 To 6) As Single Dim PlayX(0 To 3) As Single Dim PlayY(0 To 3) As Single ViewQtX = 0 ViewQtY = 0 SheetWidth = ActiveSheet.Width - SheetPlayX - play_between_views SheetHeight = ActiveSheet.Height - SheetPlayY - play_between_views View(1)="VIEW1" View(2)="VIEW2" View(3)="VIEW3" View(4)="VIEW4" View(5)="VIEW5" View(6)="VIEW6" CurrentScale = ActiveSheet.View(View(1)).Scale For i=1 To 6 Try ViewHeight(i) = ActiveSheet.View(View(i)).Height * (1 / CurrentScale) ViewWidth(i) = ActiveSheet.View(View(i)).Width * (1 / CurrentScale) Catch ViewHeight(i)=0 ViewWidth(i)=0 End Try Next MaxWidth = ViewWidth(5) + ViewWidth(1) + ViewWidth(3) MaxHeight = ViewHeight(4) + ViewHeight(1) + ViewHeight(2) ScaleX = SheetWidth / MaxWidth ScaleY = SheetHeight / MaxHeight FinalScale = Min(ScaleY,ScaleX) If FinalScale <1 Then FinalScale = FinalScale^-1 mm = 1 FinalScale = Round(Round(FinalScale,2) / mm) * mm ActiveSheet.View(View(1)).ScaleString = "1/" & FinalScale ActiveSheet.View(View(6)).ScaleString="1/"&FinalScale Else mm = 1 FinalScale = Round(Round(FinalScale,2) / mm) * mm ActiveSheet.View(View(1)).Scale = FinalScale End If iProperties.Value("Custom", "Scale") = ActiveSheet.View(View(1)).ScaleString iProperties.Value("Custom", "Scale")=ActiveSheet.View(View(6)).ScaleString For i=1 To 6 Try ViewHeight(i)=ActiveSheet.View(View(i)).Height ViewWidth(i)=ActiveSheet.View(View(i)).Width Catch ViewHeight(i)=0 ViewWidth(i)=0 End Try Next MaxWidth = ViewWidth(5) + ViewWidth(1) + ViewWidth(3) MaxHeight = ViewHeight(4) + ViewHeight(1) + ViewHeight(2) If ViewWidth(5)<>0 Then NumberViewsX = NumberViewsX+1 End If If ViewWidth(1)<>0 Then NumberViewsX = NumberViewsX+1 End If If ViewWidth(3)<>0 Then NumberViewsX = NumberViewsX+1 End If If ViewHeight(4)<>0 Then NumberViewsY = NumberViewsY+1 End If If ViewHeight(1)<>0 Then NumberViewsY = NumberViewsY+1 End If If ViewHeight(2)<>0 Then NumberViewsY = NumberViewsY+1 End If PlayX(0) = (ActiveSheet.Width - MaxWidth) /(NumberViewsX+1) PlayY(0) = (ActiveSheet.Height - MaxHeight) /(NumberViewsY+1) If ViewWidth(5)<>0 Then PlayX(1) = PlayX(0) + play_between_views End If If ViewWidth(1)<>0 Then PlayX(2) = PlayX(0) + play_between_views End If If ViewHeight(2)<>0 Then PlayY(1)=PlayY(0) + play_between_views End If If ViewHeight(1)<>0 Then PlayY(2)=PlayY(0) + play_between_views End If CenterX(5)= PlayX(0) + deviation_X + ViewWidth(5)/2 CenterX(1)= CenterX(5) + ViewWidth(5)/2 + PlayX(1) + ViewWidth(1)/2 CenterX(3) = CenterX(1) + ViewWidth(1) / 2 + PlayX(2) + ViewWidth(3) / 2 CenterX(2)= CenterX(1) CenterX(4) = CenterX(1) CenterX(6) = CenterX(3)-60 CenterY(2)= PlayY(0) + deviation_Y + ViewHeight(2)/2 CenterY(1)= CenterY(2) + ViewHeight(2)/2 + PlayY(1) + ViewHeight(1)/2-70 CenterY(4)= CenterY(1) + ViewHeight(1)/2 + PlayY(2) + ViewHeight(4)/2+20 CenterY(5)=CenterY(1) CenterY(3) = CenterY(1) CenterY(6) = CenterY(4) -60 For i=1 To 6 Try ActiveSheet.View(View(i)).SetCenter(CenterX(i),CenterY(i)) Catch End Try Next Dim oDoc As DrawingDocument oDoc = ThisApplication.ActiveDocument scaleview6 =CurrentScale InventorVb.DocumentUpdate()
Solved! Go to Solution.
Link copied