Hidden Lines in Drawing

Programming and macros
MJuric
Posts: 1067
Joined: Mon Mar 08, 2021 3:21 pm
Answers: 1
x 31
x 873

Hidden Lines in Drawing

Unread post by MJuric »

What's the magic ticket that causes hidden lines to show up when you create a drawing using the API?

I created a quick macro to create a drawing and set "Hidden lines visible" when I recorded it and then when I ran it...no hidden lines.

I looked up a couple things and tried them and....no hidden lines.

Is there a way to do this?

Thank You
User avatar
SPerman
Posts: 1819
Joined: Wed Mar 17, 2021 4:24 pm
Answers: 13
x 2003
x 1677
Contact:

Re: Hidden Lines in Drawing

Unread post by SPerman »

-
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
MJuric
Posts: 1067
Joined: Mon Mar 08, 2021 3:21 pm
Answers: 1
x 31
x 873

Re: Hidden Lines in Drawing

Unread post by MJuric »

SPerman wrote: Tue Sep 05, 2023 1:25 pm Does any of this help?

https://help.solidworks.com/2018/englis ... ple_vb.htm
I did mess with that a bit but my VBA skills are novice at best and it did not seem to work, or I could not get it to work. I also found a couple other places that had a few other suggestions but was also unsuccessful, again, most likely due to my lack of skills.

I will look at that again and see if it makes any more sense to me or I have any more luck, it is after all after the holiday :-)
User avatar
josh
Posts: 249
Joined: Thu Mar 11, 2021 1:05 pm
Answers: 11
x 19
x 440

Re: Hidden Lines in Drawing

Unread post by josh »

Recording is useless about 80% of the time. It doesn't capture everything you do, and often the methods it uses are not the right thing if you're writing a macro.

What does your code look like now?
MJuric
Posts: 1067
Joined: Mon Mar 08, 2021 3:21 pm
Answers: 1
x 31
x 873

Re: Hidden Lines in Drawing

Unread post by MJuric »

josh wrote: Tue Sep 05, 2023 2:42 pm Recording is useless about 80% of the time. It doesn't capture everything you do, and often the methods it uses are not the right thing if you're writing a macro.
I completely agree but in my case, IE just learning and or just trying to get something done, it's a good "starting point".
josh wrote: Tue Sep 05, 2023 2:42 pm What does your code look like now?
To your eyes I'm sure a complete and utter disaster :-) I've attached the entire macro and the pasted the specific part for the drawings below.

Right now I have a macro that.

1) Opens and closes one of our large models, opens and closes it's drawing.
2) records the time
3) Re-Opens the large model. Rotates it as if you were using the arrow keys and then rotates it as if using a mouse. Then closes the model.
4) Records the time.
5) Opens a separate model, arrays the entire model, Closes it.
6) Records the time
7) Opens a part and arrays a feature in that part, closes it
8) Records the time
9) Opens a template, places three views and an ISO view (I wanted hidden lines on but it does not show them), closes the drawing
10) Records the time

...Done

This is the part that creates a drawing.


' New Document

swSheetWidth = 1.1176

swSheetHeight = 0.8636
Set Part = swApp.NewDocument("U:\Eng-Dept\SolidWorks Templates\TEMPLATES\E-SIZE (08_29_12).drwdot", 5, swSheetWidth, swSheetHeight)

Status = swApp.RunCommand(swCommands_e.swCommands_Comp_Display_Hiddenremoved, "")


Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Set swDrawing = Part
Set swDrawing = Part

Set swDraw = swModel
Set swSheet = swDrawing.GetCurrentSheet()
swSheet.SetProperties2 12, 12, 1, 1, False, swSheetWidth, swSheetHeight, True
swSheet.SetTemplateName "\\Ame-server17\engineering2\Eng-Dept\SolidWorks Templates\AME E-Size INCH.slddrt"
swSheet.ReloadTemplate True
swApp.ActivateDoc2 "Draw3 - Sheet1", False, longstatus
Set Part = swApp.ActiveDoc

Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized

' Zoom To Fit
Part.ViewZoomtofit2

' Zoom To Fit
Part.ViewZoomtofit2

Set swDraw = swModel
Set myView = Part.CreateDrawViewFromModelView3("C:\Temp\MacroTest\Models\AMS-600SR-01-3000_MT.SLDASM", "*Front", 0.218819956036135, 0.224195426336538, 0)
boolstatus = Part.ActivateView("Drawing View1")
boolstatus = Part.Extension.SelectByID2("Drawing View1", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)
Set myView = Part.CreateUnfoldedViewAt3(0.218819956036135, 0.572584285932083, 0, False)
Part.ClearSelection2 True
boolstatus = Part.ActivateSheet("Sheet1")
boolstatus = Part.Extension.SelectByID2("Drawing View1", "DRAWINGVIEW", 0.30781648714777, 0.226366073436822, 0, False, 0, Nothing, 0)
boolstatus = Part.ActivateView("Drawing View1")
Set myView = Part.CreateUnfoldedViewAt3(0.644266787691754, 0.224195426336538, 0, False)
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Drawing View1", "DRAWINGVIEW", 0.30781648714777, 0.226366073436822, 0, False, 0, Nothing, 0)
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Drawing View1", "DRAWINGVIEW", 0.283939369044648, 0.263267074141646, 0, False, 0, Nothing, 0)
Set myView = Part.CreateUnfoldedViewAt3(0.6882223914725, 0.693597861772903, 0, False)
Part.ClearSelection2 True
boolstatus = Part.ActivateSheet("Sheet1")
boolstatus = Part.ActivateView("Drawing View2")


Set myView = Part.CreateSectionViewAt5(0.43479934251437, 0.571015877430554, 0, "A", 128, (excludedComponents), 0)
boolstatus = Part.ActivateView("Drawing View5")
Part.ClearSelection2 True

' Save As
longstatus = Part.SaveAs3("C:\Temp\MacroTest\Models\AMS-600SR-01-3000_MT_Results.SLDDRW", 0, 0)

' Close Document
Set swDrawing = Nothing
Set Part = Nothing
swApp.CloseDoc "AMS-600SR-01-3000_MT_Results - Sheet1"

endTime = Timer

elapsedTime = endTime - startTime

xlSheet.Cells(2, 5) = elapsedTime
ActiveWorkbook.Save

xlApp.Workbooks.Close
xlApp.Quit
Attachments
PerformanceTest.swp
(120 KiB) Downloaded 22 times
User avatar
SPerman
Posts: 1819
Joined: Wed Mar 17, 2021 4:24 pm
Answers: 13
x 2003
x 1677
Contact:

Re: Hidden Lines in Drawing

Unread post by SPerman »

I would try adding this

swDraw.ViewDisplayHidden

after

Set swDraw = swModel
-
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
MJuric
Posts: 1067
Joined: Mon Mar 08, 2021 3:21 pm
Answers: 1
x 31
x 873

Re: Hidden Lines in Drawing

Unread post by MJuric »

SPerman wrote: Tue Sep 05, 2023 3:56 pm I would try adding this

swDraw.ViewDisplayHidden

after

Set swDraw = swModel
I've not tried this in my full macro but I tried it in my "Small chunk I worked on to do this part" and I get... I can try it in the full version but it takes ~30 minutes to run so I try to do it in a smaller bit.
image.png
Dim swApp As Object

Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Sub main()

Set swApp = Application.SldWorks


' New Document
Dim swSheetWidth As Double
swSheetWidth = 1.1176
Dim swSheetHeight As Double
swSheetHeight = 0.8636
Set Part = swApp.NewDocument("U:\Eng-Dept\SolidWorks Templates\TEMPLATES\E-SIZE (08_29_12).drwdot", 5, swSheetWidth, swSheetHeight)

Status = swApp.RunCommand(swCommands_e.swCommands_Comp_Display_Hiddenremoved, "")

Dim swDrawing As DrawingDoc
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Set swDrawing = Part
Set swDrawing = Part
Dim swSheet As sheet
Set swDraw = swModel
swDraw.ViewDisplayHidden
Set swSheet = swDrawing.GetCurrentSheet()
swSheet.SetProperties2 12, 12, 1, 1, False, swSheetWidth, swSheetHeight, True
swSheet.SetTemplateName "\\Ame-server17\engineering2\Eng-Dept\SolidWorks Templates\AME E-Size INCH.slddrt"
swSheet.ReloadTemplate True
swApp.ActivateDoc2 "Draw3 - Sheet1", False, longstatus
Set Part = swApp.ActiveDoc
Dim myModelView As Object
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized

' Zoom To Fit
Part.ViewZoomtofit2

' Zoom To Fit
Part.ViewZoomtofit2
Dim myView As Object
Set swDraw = swModel
Set myView = Part.CreateDrawViewFromModelView3("C:\Temp\MacroTest\Models\AMS-600SR-01-3000_MT.SLDASM", "*Front", 0.218819956036135, 0.224195426336538, 0)
boolstatus = Part.ActivateView("Drawing View1")
boolstatus = Part.Extension.SelectByID2("Drawing View1", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)
Set myView = Part.CreateUnfoldedViewAt3(0.218819956036135, 0.572584285932083, 0, False)
Part.ClearSelection2 True
boolstatus = Part.ActivateSheet("Sheet1")
boolstatus = Part.Extension.SelectByID2("Drawing View1", "DRAWINGVIEW", 0.30781648714777, 0.226366073436822, 0, False, 0, Nothing, 0)
boolstatus = Part.ActivateView("Drawing View1")
Set myView = Part.CreateUnfoldedViewAt3(0.644266787691754, 0.224195426336538, 0, False)
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Drawing View1", "DRAWINGVIEW", 0.30781648714777, 0.226366073436822, 0, False, 0, Nothing, 0)
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Drawing View1", "DRAWINGVIEW", 0.283939369044648, 0.263267074141646, 0, False, 0, Nothing, 0)
Set myView = Part.CreateUnfoldedViewAt3(0.6882223914725, 0.693597861772903, 0, False)
Part.ClearSelection2 True
boolstatus = Part.ActivateSheet("Sheet1")
boolstatus = Part.ActivateView("Drawing View2")

Dim excludedComponents As Variant
Set myView = Part.CreateSectionViewAt5(0.43479934251437, 0.571015877430554, 0, "A", 128, (excludedComponents), 0)
boolstatus = Part.ActivateView("Drawing View5")
Part.ClearSelection2 True

' Save As
longstatus = Part.SaveAs3("C:\Temp\MacroTest\Models\AMS-600SR-01-3000_MT_Results.SLDDRW", 0, 0)
End Sub
User avatar
josh
Posts: 249
Joined: Thu Mar 11, 2021 1:05 pm
Answers: 11
x 19
x 440

Re: Hidden Lines in Drawing

Unread post by josh »

So you have a few lines here that say "Set myView = "....

After this point, myView is a direct reference to that drawing view that gets created. Well, at least it is until later when you say "Set myView ="... something different.
So myView is a View object, so you can use all the properties and methods of the View object on it. One of the Methods of the View is "SetDisplayMode4". The proper arguments for this method are shown in the help, along with an example.
User avatar
SPerman
Posts: 1819
Joined: Wed Mar 17, 2021 4:24 pm
Answers: 13
x 2003
x 1677
Contact:

Re: Hidden Lines in Drawing

Unread post by SPerman »

Maybe it needs parenthesis on the end? Hopefully one of the macro guru's will chime in. Clearly I'm just speculating.
image.png
-
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
User avatar
josh
Posts: 249
Joined: Thu Mar 11, 2021 1:05 pm
Answers: 11
x 19
x 440

Re: Hidden Lines in Drawing

Unread post by josh »

SPerman wrote: Tue Sep 05, 2023 4:36 pm Maybe it needs parenthesis on the end? Hopefully one of the macro guru's will chime in. Clearly I'm just speculating.

image.png
Well... The main reason it was failing is that swModel is never set to anything. Therefore the swModel is the empty object variable value of Nothing. Therefore, "Set swDraw = swModel" sets swDraw equal to Nothing. This is totally valid code-wise until you get to the line where you actually ask swDraw to do something - swDraw.ViewDisplayHidden. Since swDraw references Nothing, and Nothing doesn't have the method ViewDisplayHidden, that's the line that gets an error.
Post Reply