- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @dypro. When the Value of the AutoCADBlock's attribute is empty, do you still want to create a custom iProperty for that attribute, even though it could not be assigned a value? If you would like to simply skip over any attributes that do not have a value, we could check for that just before the Select Case block of code starts, like this:
For i As Integer = 0 To UBound(oPromptTags)
Dim sPromptTag As String = oPromptTags(i)
Dim sValue As String = oValues(i)
If sValue = "" Then Continue For
...that last line would be the only new line needed to make that happen.
However, if you do want to still create the custom iProperty for that attribute, even if its value is empty, then there are some options about how to proceed. Obviously the first thing we would need to check is 'sValue', to see if it is either empty, or if its contents are convertable to the Date data type. I wrote out some code, as an alternate example, to help avoid these problems, but I'm sure this code could have been written more efficiently. I was just in a hurry because I've got a lot of other stuff going on at the moment. You will notice an additional check in there (IsDate), which can be used to determine if the provided data can be understood as, or converted to, the Date type. Also, in order to keep the code condensed, I am using a lot of ':' (colon) symbols in there to combine multiple lines of code into fewer lines, but feel free to expand that stuff out if you want to. And if you need more feedback in order to be able to tell exactly what all is happening, feel free to throw some Logger.Info("some information") type lines in there. I often use the Logger a lot in new codes, then eliminate them later, once I'm comfortable doing so.
Case "SH_DATE_MODIF"
Dim bFoundRev As Boolean = False
Dim dModifDate As Date
Try : oCProp = oCProps.Item("FECHA REVISION") : bFoundRev = True : Catch : End Try
If IsNothing(oCProp) Then
If sValue = "" OrElse IsDate(sValue) = False Then
Try : oCProp = oCProps.Add(sValue, "FECHA REVISION") : Catch : End Try
ElseIf sValue <> "" AndAlso IsDate(sValue) = True Then
Try : dModifDate = Convert.ToDateTime(sValue) : Catch : End Try
Try : oCProp = oCProps.Add(dModifDate, "FECHA REVISION") : Catch : End Try
End If
End If
If bFoundRev = True Then
If sValue = "" OrElse IsDate(sValue) = False Then
If oCProp.Value <> sValue Then Try : oCProp.Value = sValue : Catch : End Try
ElseIf sValue <> "" AndAlso IsDate(sValue) = True Then
Try : dModifDate = Convert.ToDateTime(sValue) : Catch : End Try
If oCProp.Value <> dModifDate Then Try : oCProp.Value = dModifDate : Catch : End Try
End If
End If
Wesley Crihfield
(Not an Autodesk Employee)