Macro for tangent edges and high quality views

Library for macros
User avatar
nuevahola
Posts: 13
Joined: Tue Jan 04, 2022 5:21 pm
Answers: 0
Location: Spain
x 3
x 11

Macro for tangent edges and high quality views

Unread post by nuevahola »

I'm in the need of finding a fast way for turning on the tangent edges of a drawing, and it would be great if I could also set the quality of the view as high. Does anybody have a macro for this?. I know I can set the quality of the view as high through the task scheduler but I can't find any other way for turning on the edges than manually.

Thanks
User avatar
zwei
Posts: 701
Joined: Mon Mar 15, 2021 9:17 pm
Answers: 18
Location: Malaysia
x 185
x 600

Re: Macro for tangent edges and high quality views

Unread post by zwei »

Do you want to turn on the tangent edge for ALL existing drawing view?
This most probably will require iterate through all your view

Or do you want to turn the tangent edge for all new drawing view created?
This normally just involve turning on a system setting
Far too many items in the world are designed, constructed and foisted upon us with no understanding-or even care-for how we will use them.
User avatar
nuevahola
Posts: 13
Joined: Tue Jan 04, 2022 5:21 pm
Answers: 0
Location: Spain
x 3
x 11

Re: Macro for tangent edges and high quality views

Unread post by nuevahola »

I have a client that sends me every drawing like that, so i need to convert every view of every drawing..
Zhen-Wei Tee wrote: Mon Oct 24, 2022 7:34 pm Do you want to turn on the tangent edge for ALL existing drawing view?
This most probably will require iterate through all your view

Or do you want to turn the tangent edge for all new drawing view created?
This normally just involve turning on a system setting
User avatar
zwei
Posts: 701
Joined: Mon Mar 15, 2021 9:17 pm
Answers: 18
Location: Malaysia
x 185
x 600

Re: Macro for tangent edges and high quality views

Unread post by zwei »

I drafted a quick macro that change the tangent edge display to TangentEdge with Font and also change the view quality to high
Change the line in red to change setting
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swSheet As SldWorks.Sheet

Dim i As Integer
Dim j As Integer
Dim vViews As Variant
Dim swView As SldWorks.View
Dim swModView As SldWorks.ModelView
Dim bRet As Boolean

Sub main()

Set swApp = Application.SldWorks

try_:
On Error GoTo catch_:

Set swModel = swApp.ActiveDoc

If swModel Is Nothing Then
MsgBox "Please open a drawing first.", vbCritical, "ERROR"
End
End If

If swModel.GetType() = swDocDRAWING Then
Set swDraw = swModel
SetTangentEdge swDraw
GoTo finally_

Else
MsgBox "Macro only works on drawing.", vbCritical, "ERROR"
Set swModel = Nothing
End
End If

catch_:
swApp.SendMsgToUser2 Err.Description, swMessageBoxIcon_e.swMbStop, swMessageBoxBtn_e.swMbOk

finally_:

Set swModel = Nothing

End Sub

Sub SetTangentEdge(draw As SldWorks.DrawingDoc)


vSheets = draw.GetViews

For i = 0 To UBound(vSheets)


vViews = vSheets(i)

For j = 0 To UBound(vViews)


Set swView = vViews(j)

'Display tangent setting:
'swTangentEdgesHidden
'swTangentEdgesVisible
'swTangentEdgesVisibleAndFonted

swView.SetDisplayTangentEdges2 swTangentEdgesVisibleAndFonted

'SetDisplayMode3(UseParent, Mode, Facetted, Edges)
'facetted set to false to use precise (HLR)
bRet = swView.SetDisplayMode3(swView.GetUseParentDisplayMode, swView.GetDisplayMode2, False, swView.GetDisplayEdgesInShadedMode)



Next

Next

End Sub
Far too many items in the world are designed, constructed and foisted upon us with no understanding-or even care-for how we will use them.
User avatar
nuevahola
Posts: 13
Joined: Tue Jan 04, 2022 5:21 pm
Answers: 0
Location: Spain
x 3
x 11

Re: Macro for tangent edges and high quality views

Unread post by nuevahola »

It works just perfect!.

Thank you very much.
Cimthog
Posts: 1
Joined: Fri Dec 02, 2022 9:47 am
Answers: 0
x 1

Re: Macro for tangent edges and high quality views

Unread post by Cimthog »

Well done! It worked perfectly here too. Thank you!
sooz
Posts: 3
Joined: Wed May 03, 2023 1:35 pm
Answers: 0
Location: Colorado
x 1

Re: Macro for tangent edges and high quality views

Unread post by sooz »

Any chance there is a way to set this to exclude any ISOMETRIC Views?
User avatar
zwei
Posts: 701
Joined: Mon Mar 15, 2021 9:17 pm
Answers: 18
Location: Malaysia
x 185
x 600

Re: Macro for tangent edges and high quality views

Unread post by zwei »

sooz wrote: Wed May 03, 2023 1:36 pm Any chance there is a way to set this to exclude any ISOMETRIC Views?
this depends on HOW the isoview is created...

As far as i know, solidworks does not differentiate whether the view is iso/trimetric/dimetric/etc. It could only identify whether it is named view or projected view...

However,
If the is created as a "standalone view" (Model view → Select Isometric and place view), the iso view is a named view and uses true dimension by default. So you should be able to use a standard IF condition to determine whether it is a stanalone iso view and exclude it. However, this does not work if the isoview is created by projecting off a standard view

https://help.solidworks.com/2012/englis ... sions.html
https://help.solidworks.com/2012/englis ... pes_e.html

macro snippet example below
Sub SetTangentEdge(draw As SldWorks.DrawingDoc)


vSheets = draw.GetViews

For i = 0 To UBound(vSheets)


vViews = vSheets(i)

For j = 0 To UBound(vViews)


Set swView = vViews(j)

If swView.Type = swDrawingNamedView And swView.ProjectedDimensions = False Then
'Skip if standalone isoview

Else

'Display tangent setting:
'swTangentEdgesHidden
'swTangentEdgesVisible
'swTangentEdgesVisibleAndFonted
swView.SetDisplayTangentEdges2 swTangentEdgesVisibleAndFonted
'SetDisplayMode3(UseParent, Mode, Facetted, Edges)
'facetted set to false to use precise (HLR)
bRet = swView.SetDisplayMode3(swView.GetUseParentDisplayMode, swView.GetDisplayMode2, False, swView.GetDisplayEdgesInShadedMode)
'swView.SetDisplayTangentEdges2 swTangentEdgesVisibleAndFonted

End If

Next
Next

End Sub
Far too many items in the world are designed, constructed and foisted upon us with no understanding-or even care-for how we will use them.
User avatar
gupta9665
Posts: 405
Joined: Thu Mar 11, 2021 10:20 am
Answers: 25
Location: India
x 426
x 445

Re: Macro for tangent edges and high quality views

Unread post by gupta9665 »

GetOrientationName method should help in finding the view pre defined name only if it has been created independently.
Deepak Gupta
SOLIDWORKS Consultant/Blogger
Post Reply