Robke Posted April 24, 2013 Posted April 24, 2013 Hi guys, I'm new here and in programming also. I need to create a programm which should check a drawing. The check means, that we have 3 different layers: contour, axes and section. As you know all of them must have different lines thickness. So, let's imagine that thickness should be: 0,5mm 1mm ant 2mm. Is it possible to create such a program, which, when user selects any line or selects any layer in the drawing, my programm checks this solution and changes automatically thickness of the layer lines? If yes, how can I do it? any suggestions? Quote
ReMark Posted April 24, 2013 Posted April 24, 2013 Have you looked into using the Standards Checker feature in AutoCAD. It might save you some work. Quote
Robke Posted April 24, 2013 Author Posted April 24, 2013 Thanks for your advise, but i need to work with *.dwg files not *.dws As i untertand i need to write code, that checks selected layer or line, with parameters in my programm 0,5 1 2 mm and colours red green and blue. if contour is red and thickness is 0,7, its a problem. my program must change thickness to 0,5 and leave current colour. As i understand all of checks must be done on layer name? isn't it? Quote
ReMark Posted April 24, 2013 Posted April 24, 2013 The CHECKSTANDARDS command can be used to check a drawing (DWG) for violations. Violations can then be fixed automatically, manually or ignored. If you want to do this via VBA programming then by all means carry on. Maybe one of the programming gurus here can help get you started. Good luck with your project. Quote
Robke Posted April 24, 2013 Author Posted April 24, 2013 thanks for helpReMark Programming gurus are my last hope... Quote
BlackBox Posted April 24, 2013 Posted April 24, 2013 thanks for helpReMark Programming gurus are my last hope... If dealing with internal workstations, you could instead use a Reactor/Event Handler to detect changes made to the Layer Objects, and programmatically restore the desired settings (which gives the user the illusion that the changes made are not taking affect)... But since you're new to programming, you should revisit the Standards Command option, methinks. Good luck! Quote
Robke Posted April 30, 2013 Author Posted April 30, 2013 Hi guys one more time.... i wrote my programm code... now i need to do this: is it possible to create a procedure or smth that my programm will starts if user clicks on drawing (i mean line) or clicks on layers in autocad? now my programm works if i starts macros (vba) and click on a button that i created in a form... i need to create smth that my programm will start automatically Quote
Robke Posted May 22, 2013 Author Posted May 22, 2013 hi guys, i have two questions for you. this is my simple VBA code for my exercise. i want to ask what i'm doing wrong, because then i load a *.dwg file and run macros, i get always Else statement. I don't know why... so how do i need to compare layer name which is string correctly to get the correct if elseif or else statement? and the second question is, is it possible to write something that this kind of program will run automatically then i select layer on autocad? Private Sub CommandButton1_Click() Dim strLayerKonturas As String Dim strLayerAsys As String Dim strLayerMatmenys As String Dim objLayer As AcadLayer Dim intColor As Integer strLayerKonturas = "konturas" strLayerAsys = "Asys" strLayerMatmenys = "Matmenys" 'For Each objLayer In ThisDrawing.Layers If "" = strLayerKonturas Then ' exit if no name entered If objLayer.Color = acRed Xor objLayer.Linetype = "Continuous" Xor objLayer.Lineweight = acLnWt050 Then MsgBox "Sluoksnis: '" & objLayer.Name & "' tvarkoj" Else: objLayer.Color = acRed objLayer.Linetype = "Continuous" objLayer.Lineweight = acLnWt050 objDrawingObject.Update MsgBox "Sluoksnis: '" & objLayer.Name & "' pertvarkytas" End If Else: MsgBox "Nera Konturo." End If ' If "" = strLayerAsys Then 'Exit Sub ' exit if no name entered ' On Error Resume Next ' handle exceptions inline ' Set objLayer = ThisDrawing.Layers(strLayerAsys) ' If objLayer.Color = acGreen Xor objLayer.Linetype = "CENTER" Xor objLayer.Lineweight = acLnWt025 Then ' MsgBox "Sluoksnis: '" & objLayer.Name & "' tvarkoj" ' ElseIf objLayer.Color <> acGreen Xor objLayer.Linetype <> "CENTER" Xor objLayer.Lineweight <> acLnWt025 Then ' objLayer.Color = acGreen ' objLayer.Linetype = "CENTER" ' objLayer.Lineweight = acLnWt025 ' MsgBox "Sluoksnis: '" & objLayer.Name & "' pertvarkytas" ' End If ' Else: MsgBox "Nera asiu" ' End If ' If "" = strLayerMatmenys Then 'Exit Sub ' exit if no name entered 'On Error Resume Next ' handle exceptions inline ' Set objLayer = ThisDrawing.Layers(strLayerMatmenys) ' If objLayer.Color = acBlue Xor objLayer.Linetype = "Continuous" Xor objLayer.Lineweight = acLnWtByLwDefault Then ' MsgBox "Sluoksnis: '" & objLayer.Name & "' tvarkoj" ' ElseIf objLayer.Color <> acBlue Xor objLayer.Linetype <> "Continuous" Xor objLayer.Lineweight <> acLnWtByLwDefault Then ' objLayer.Color = acBlue ' objLayer.Linetype = "Continuous" ' objLayer.Lineweight = acLnWtByLwDefault '' MsgBox "Sluoksnis: '" & objLayer.Name & "' pertvarkytas" ' End If '' Else: MsgBox "ner gaidze" '' End If ' ElseIf ("" <> strLayerAsys) And ("" <> strLayerKonturas) And ("" <> strLayerMatmenys) Then ' MsgBox "Brezinyje privalo buti trys sluoksniai: Asys, Konturas, Matmenys. Prasome pertvarkyti brezini" 'End If End Sub Quote
btraemoore Posted May 29, 2013 Posted May 29, 2013 I wrote some stuff in vba when i was first learning. attached is a full project that compares and changes several different properties of layers and linetypes from a text file that is included in the zip. Remember this is not a load and run. You will need to modify the project, but you can look at the syntax and get some good examples of how things should be structured. good luck... and remember, although there are not many resources for autocad vba online... google is your best friend... cheers vba-custom.zip Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.